﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib tagdir="/WEB-INF/tags/ssmp" prefix="ssmp" %>
<%@ page import="com.csis.ssmp.sys.domain.User" %>
<%
    User user = (User)session.getAttribute("userInfo");
    String maAssoCode = user.getMaAssoCode();
    if(maAssoCode == null){ maAssoCode = ""; }
%>
<style>
    .csis-fee-rbg1 .x-grid-cell {
        background-color: rgb(204,192,218);
    }
    .csis-fee-rbg2 .x-grid-cell {
        background-color: rgb(252,213,180);
    }

</style>
<script>
    Ext.Loader.loadScript("/res/js/feeinvoiceExtend.js?v=<%=Math.random()%>")
</script>
<script>
    CSIS.namespace('fmm.feeinvoice2', function () {
        Ext.onReady(function () {
            var userCode = '<%=user.getUsrCode()%>';
            var userName = '<%=user.getUsrName()%>';
            var companyCode = '<%=user.getCompanyCode()%>';
            var maAssoCode = '<%=maAssoCode%>';//用户联营公司代码
            var menuNo = '<%=request.getRequestURI()%>';
            var currentId = C.currentPageId;
            var btnStatus='';
            var orderNo = '<%=request.getParameter("orderNo")%>';
            var recordDataId = '<%=request.getParameter("recordDataId")%>';

            var bndFlag = false;//判断是否为绑垫料费用
            var htwlcgFlag = false;//判断是否维特运物料项目组采购角色
            if (companyCode.startWith('6500')&&(checkUserDept('3',userCode,"绑垫料采购项目组")||checkUserDept('3',userCode,"绑垫料与支墩采购主管"))) {
                bndFlag = true;
            }
            if (companyCode.startWith('6500')&&checkUserDept('3',userCode,"物料采购项目组")) {
                htwlcgFlag = true;
            }

            //获取页面按钮权限
            <ssmp:permissionMap pageNo="fmm.feeinvoice2"/>
            var youlunFlag = !isEmpty(companyCode) && (companyCode.substring(0,4)=='0802'||companyCode.substring(0,4)=='0811'||(companyCode.substring(0,2)=='62'&&!companyCode.startWith("6207")));  //是否能源公司
            //散运 、发展
            var sanyunFlag = !isEmpty(companyCode) && ( (companyCode.substring(0,4)=='0801') || companyCode.substring(0,2)=='01' || companyCode.substring(0,2)=='66') ;
            var daYuanFlag = !isEmpty(companyCode) && (companyCode.substring(0,4)=='6203'||companyCode.substring(0,4)=='6221'); //是否大远公司用户登录 (大连华昌)
            //是否天津公司用户登录
            var tianjinFlag = !isEmpty(companyCode) && ((companyCode.substring(0,2)=='6600')||(companyCode.substring(0,4)=='0801'));
            var tianjinFlagTwo = !isEmpty(companyCode) && (companyCode.substring(0,4)=='6601');
            var haiteFlag = !isEmpty(companyCode) && ((companyCode.substring(0,2)=='65')||(companyCode.substring(0,2)=='63')||(companyCode.substring(0,2)=='68'));
            var xiamenFlag = !isEmpty(companyCode) && (companyCode.substring(0,2)=='63');
            var IsYYfee =false;
            if("辛钢"==userName || "张欣" ==userName||"王洪波"==userName){ IsYYfee=true;}
            //备件订购界面参数
            var enquireNo = '<%=request.getParameter("enquireNo")%>';
            var pageVesselCode = '<%=request.getParameter("pageVesselCode")%>';
            var enquireType = '<%=request.getParameter("enquireType")%>';
            var cusType = '<%=request.getParameter("cusType")%>';
            var completionReportId='<%=request.getParameter("completionReportId")%>'
            var applyBusiType = '<%=request.getParameter("applyBusiType")%>'
            var isWlOrderCreate = false;
            var isBjOrderCreate = false;
            var currencyMap = new CSIS.HashMap()
            var billNoFlag = false;//判断是否内部订单号选择：是就不再加载关联信息数据；否则继续加载
            var rpt_order_no = '<%=request.getParameter("rpt_order_no")%>'
            var rpt_inner_order = '<%=request.getParameter("rpt_inner_order")%>'//散运结算单监控表跳转使用

            var codedictMaps = getCodedictMaps("FMM_TAX_ONLINE_COMPANY,FMM_INV_GROUP_SORT,FMM_INV_GROUP_SORT_DETAIL,FMM_ORDER_FEE_VALIDATE")
            var invoiceCheckCompanyMap = codedictMaps['FMM_TAX_ONLINE_COMPANY'];

            function setButtonStatus(type,enable){
                if(!type){   //初始化的时候
                    page.getToolbarBox().setAllButtonsStatus(C.ToolBarStatus.ALL_DISABLE);
                    btnMainAdd.setDisabled(true);btnMainEdit.setDisabled(true);btnMainRemove.setDisabled(true);btnNegReversal.setDisabled(true);      //负冲销按钮
                    btnPaymentNotice.setDisabled(true); btnOperation.setDisabled(true);btnNegReversal_sub.setDisabled(true);      //负冲销按钮
                    btnPaymentNotice_sub.setDisabled(true);btnOperation_sub.setDisabled(true);btnExport.setDisabled(true);          //导出签收单按钮
                    rebackUpdateBtn.setDisabled(true);doubtOrRevokeBtn.setDisabled(true);doubtOrRevokeBtn_sub.setDisabled(true);
                    rejectInvoiceBtn.setDisabled(true);rejectInvoiceBtn_sub.setDisabled(true);
                    attachmentTwoUploadInputBtn.hide();attachmentTwoUploadBtn.hide()
                }
                if(!permissionMap.containsKey("dataModBtn")){
                    dataModBtn.hide();
                }
                if(type == 'create'){
                    btnMainAdd.setDisabled(true);
                    isCreate = false;
                    page.getToolbarBox().getButton('create').setDisabled(true)
                    if(permissionMap.containsKey('btnCreate')){
                        page.getToolbarBox().getButton('create').setDisabled(!enable)
                        btnMainAdd.setDisabled(!enable); }
                }
                if(type == 'edit'){
                    isEdit = false
                    btnMainEdit.setDisabled(true);
                    page.getToolbarBox().getButton('edit').setDisabled(true)
                    if(permissionMap.containsKey('btnEdit')){
                        page.getToolbarBox().getButton('edit').setDisabled(!enable);
                        btnMainEdit.setDisabled(!enable);}
                }
                if(type == 'remove'){
                    btnMainRemove.setDisabled(true);
                    page.getToolbarBox().getButton('remove').setDisabled(true)
                    if(permissionMap.containsKey('btnRemove')){
                        page.getToolbarBox().getButton('remove').setDisabled(!enable)
                        btnMainRemove.setDisabled(!enable);}
                }
                if(type == 'negRev'){
                    btnNegReversal.setDisabled(true)
                    if(permissionMap.containsKey('btnNegRev')){
                        btnNegReversal.setDisabled(!enable)
                        btnNegReversal_sub.setDisabled(!enable)}
                }
                if(type == 'payNoti'){
                    btnPaymentNotice.setDisabled(true)
                    if(permissionMap.containsKey('btnPayNoti')){
                        btnPaymentNotice.setDisabled(!enable)
                        btnPaymentNotice_sub.setDisabled(!enable)}
                }
                if(type == 'opera'){
                    btnOperation.setDisabled(true)
                    if(permissionMap.containsKey('btnOpera')){
                        btnOperation.setDisabled(!enable)
                        btnOperation_sub.setDisabled(!enable)}
                }
                if(type == 'btnExport'){
                    btnExport.setDisabled(true)
                    if(permissionMap.containsKey('btnExport'))
                        btnExport.setDisabled(!enable)
                }
                if(type=='rebackUpdateBtn'){
                    rebackUpdateBtn.setDisabled(true)
                    if(permissionMap.containsKey('rebackUpdateBtn'))
                        rebackUpdateBtn.setDisabled(!enable)
                }
                if(type=='doubtOrRevokeBtn'){
                    doubtOrRevokeBtn.setDisabled(true)
                    doubtOrRevokeBtn_sub.setDisabled(true)
                    if(permissionMap.containsKey('doubtOrRevokeBtn')){
                        doubtOrRevokeBtn.setDisabled(!enable)
                        doubtOrRevokeBtn_sub.setDisabled(!enable)
                    }
                }
                if(type=="rejectInvoiceBtn"){
                    rejectInvoiceBtn.setDisabled(true)
                    rejectInvoiceBtn_sub.setDisabled(true)
                    if(permissionMap.containsKey('rejectInvoiceBtn')){
                        rejectInvoiceBtn.setDisabled(!enable)
                        rejectInvoiceBtn_sub.setDisabled(!enable) }
                }

                if(type=="btnViewInnerOrder"){
                    btnViewInnerOrder.setDisabled(true)
                    rejectInvoiceBtn_sub.setDisabled(true)
                    if(permissionMap.containsKey('btnViewInnerOrder')){
                        btnViewInnerOrder.setDisabled(!enable)
                        rejectInvoiceBtn_sub.setDisabled(!enable) }
                }
                if(type=="attachmentTwoUploadInputBtn"){
                    attachmentTwoUploadInputBtn.hide()
                    if(permissionMap.containsKey('attachmentTwoUploadInputBtn')){
                        if(enable==true)attachmentTwoUploadInputBtn.show()
                        else attachmentTwoUploadInputBtn.hide()
                    }
                }
                if(type=="attachmentTwoUploadBtn"){
                    attachmentTwoUploadBtn.hide()
                    if(permissionMap.containsKey('attachmentTwoUploadBtn')){
                        if(enable==true)attachmentTwoUploadBtn.show()
                        else attachmentTwoUploadBtn.hide()
                    }
                }
            }

            function setInvoicePayer(vesselCode,date,manageType,currentCompany){
                C.ajax.callAction('callSpManagement','feeInvoice',{vesselCode:vesselCode,date:date,manageType:manageType,currentCompany:currentCompany},
                    function(action,domainName,resp){
                        if(resp && resp.rows && resp.rows.length>0){
                            page.getEditBox().getExtField('payer').setComboValue(resp.rows[0].MANAGEMENT_CODE,resp.rows[0].MANAGEMENT_NAME);
                            tempFields.put('customerName', resp.rows[0].MANAGEMENT_NAME);
                        }
                    });

            }

            var currentRecord; //记录当前行记录
            var tempFields = new C.HashMap();//记录转码值的集合
            var tempRecordLists = [];//记录根据内部订单号弹出框返回的记录的集合
            var isNeedChange = false;
            var idScanBtnChange = false;//扫描控制
            var manageBody = "";
            function vesselGridOnSelected(vesselCode,rec){   //船舶的下拉表格
                if(companyCode.startWith("0802")){
                    var vesselCode=rec.vesselCode;
                    if(vesselCode=="9632" || vesselCode=="4253"){
                        alert("该船舶寰宇卖给海南，请注意选择付款单位；交海南前发生的费用、需使用寰宇做为付款单位");
                    }
                }
                var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                var invoiceSortDetail = page.getEditBox().getExtField("invoiceSortDetail").getValue();
                if(isEmpty(companyCode)||youlunFlag || (!isEmpty(companyCode)&&companyCode.substring(0,2)=="63") || (!isEmpty(companyCode)&&companyCode.substring(0,2)=="66")){   //油运公司
                    var vesselCode = rec.vesselCode;
                    var director =  getDirector(selectFreightType,companyCode,vesselCode);
                    if(!isEmpty(director)){
                        page.getEditBox().getExtField("director").setValue(director);
                    }else{
                        page.getEditBox().getExtField("director").setComboValue(rec.engineManager,rec.engineManagerName);
                    }
                }
                tempFields.put('usrName', rec.engineManagerName);
                page.getEditBox().getExtField("department").setComboValue(rec.manageDept,rec.manageDeptName);
                tempFields.put('departmentName', rec.manageDeptName);
                manageBody = rec.manageBody;
                tempFields.put('vesselName', CSIS.lang=="EN"?rec.vesselNameEn:rec.vesselName);
                //修改付款单位取订单号返回数据的发生时间
                var enquireMainApplyDate = page.getEditBox().getExtField("occurTimeFrom").getValue()
                if(isEmpty(enquireMainApplyDate)||youlunFlag){
                    enquireMainApplyDate = new Date()
                }
                if(!isEmpty(vesselCode) && ((companyCode.startWith("65")&&(rec.costBody.startWith("65") || rec.costBody.startWith("6300")))||rec.manageBody.startWith("68")||rec.manageBody.startWith("66"))){
                    if(permissionMap.containsKey('scanBtn')) {
                        page.getEditBox().setReadOnly('invoiceNo', false);
                    }
                    scanBtn.setDisabled(false);
                    if (rec.costBody.startWith("65") || rec.costBody.startWith("6300")) {
                        page.getEditBox().setReadOnly('invoiceCode', true);
                        page.getEditBox().setReadOnly('invoiceDate', true);

                        page.getEditBox().getExtField("voyageNo").setValue('');
                        page.getEditBox().getExtField("portCode").setValue('');
                    }
                }else{
                    if(youlunFlag){
                        var srcOrderType = page.getEditBox().getExtField("srcOrderType").getValue();
                        if( (invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007')||
                                (selectFreightType=='FY06'&&srcOrderType!='1'&&srcOrderType!='2'&&srcOrderType!='3'&&srcOrderType!='13')){
                            page.getEditBox().getExtField('invoiceNo').setValue('')
                            page.getEditBox().getExtField('invoiceDate').setValue('')
                            page.getEditBox().getExtField('invoiceCode').setValue('')
                            setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode');
                        }else{
                            setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                        }
                        page.getEditBox().setValue('innerOrder',"");
                        page.getEditBox().setValue('billNo',"");
                    }
                    scanBtn.disable();
                }
                //付款单位
                if (bndFlag) {
                    setInvoicePayer(rec.vesselCode,enquireMainApplyDate,'2','<%=user.getCompanyCode()%>')
                } else {
                    setInvoicePayer(rec.vesselCode,enquireMainApplyDate,'6','<%=user.getCompanyCode()%>')
                }

            }
            //所属部门
            var fix_officeDomain = new C.Domain('vwSysOrganizationInfo', [
                {name: 'officeId'},
                {name: 'officeCode', display: CSIS.Lang.ID_110020|| '代码'},
                {name: 'officeName', display: CSIS.Lang.ID_169510|| '名称'},
                {name: 'companyCode',display: CSIS.Lang.ID_100510||'公司'}
            ], { isTree:true, orderBy: "officeCode"  });

            //船管部门
            var fix_officeTree = {
                type: 'tree',
                rootVisible: false,
                leafOnlyChecked: false,
                domain: fix_officeDomain,
                valueField: "officeCode",
                displayField: "officeName",
                dataSourceConfig:{
                    rootExpanded:false
                },
                beforeExpand: function(){
                    fix_officeDomain.getDataSource().setFixFilter({calibre: 'GL', isDept: true});
                    if(manageBody){
                        page.getEditBox().getExtField("department").refreshTree({node: manageBody});
                    }else{
                        page.getEditBox().getExtField("department").refreshTree({node: companyCode});
                    }
                },
                onSelected: function (rec,name) {
                    tempFields.put('departmentName', rec[0].officeName);
                }
            };

            var currencyDomain = new C.Domain('currency', [
                {name: 'currencyId'},
                {name: 'currency', display: CSIS.Lang.ID_107040|| '币种代码'},
                {name: 'currencyName', display: CSIS.Lang.ID_107050||'币种名称'},
                {name: 'currencyNameEn', display: CSIS.Lang.ID_107050||'币种名称'},
                {name: 'seqNo'}
            ], {
                grid: CSIS.lang=="EN"?'currency,currencyNameEn':'currency,currencyName',
                orderBy: 'seqNo'
            });

            //币种
            var currencyGrid = {
                type: 'grid',
                labelWidth:130,
                domain: currencyDomain,
                searchFields: 'currency,currencyName',    //grid中展示出来的字段
                onSelected: function (rec,name) {
                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:rec[0].data.currency,currencyTo:'CNY'},
                            function(action,domainName,resp){
                                page.getEditBox().setValue('exchangeRate',resp);
                            });
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                    if(!isEmpty(vesselCode)){ //海特的船税率、税额、增值税不随币种变化
                        C.ajax.callAction('getVesselManagemenet','vesselManagement',{vesselCode:vesselCode},function(action,domainName,resp){
                            if(!isEmpty(resp.msg)&& !resp.msg.startWith("65")){
                                if(!name.startWith('search.')){
                                    tempFields.put('currencyName', rec[0].data.currencyName);
                                    if( rec[0].data.currency!='CNY'){
                                        page.getEditBox().setValue('ifCanUseTax',"0");   //是否增值税
                                    }else{
                                        page.getEditBox().setValue("taxRate",'0.13');
                                        tempFields.put("taxRateName",'13%');
                                        page.getEditBox().setValue('exchangeRate','1');
                                        page.getEditBox().setValue('ifCanUseTax',"1");//触发setFieldDisabledCommon()
                                    }
                                }
                            }
                        });
                    }else{
                        if(!name.startWith('search.')){
                            tempFields.put('currencyName', rec[0].data.currencyName);
                            if( rec[0].data.currency!='CNY'){
                                page.getEditBox().setValue('ifCanUseTax',"0");   //是否增值税
                            }else{
                                page.getEditBox().setValue("taxRate",'0.13');
                                tempFields.put("taxRateName",'13%');
                                page.getEditBox().setValue('exchangeRate','1');
                                page.getEditBox().setValue('ifCanUseTax',"1");//触发setFieldDisabledCommon()
                            }
                        }
                    }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.currencyNameEn:rec[0].data.currencyName,
                        value: rec[0].data.currency
                    }
                }
            };

            var zfCurrencyGrid = { //币种
                type: 'grid',
                labelWidth:130,
                domain: currencyDomain,
                searchFields: 'currency,currencyName',
                onSelected: function (rec,name) {
                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:rec[0].data.currency,currencyTo:'CNY'},
                            function(action,domainName,resp){ page.getEditBox().setValue('zfExchangeRate',resp);  });
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.currencyNameEn:rec[0].data.currencyName,
                        value: rec[0].data.currency
                    }
                }
            };

            //订单币种
            var equipCurrencyGrid = {
                type: 'grid',
                labelWidth:130,
                domain: currencyDomain,
                searchFields: 'currency,currencyName',    // 检索的字段
                onSelected: function (rec,name) {
                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:rec[0].data.currency,currencyTo:'CNY'},
                            function(action,domainName,resp){
                                page.getEditBox().setValue('equipBillRate',resp);
                            });
                    if(!name.startWith('search.')){
                        tempFields.put('currencyName', rec[0].data.currencyName);
                        if( rec[0].data.currency!='CNY'){
                            page.getEditBox().setValue('equipBillRate',null);
                        }
                    }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.currencyNameEn:rec[0].data.currencyName,
                        value: rec[0].data.currency
                    }
                }
            };
            if(maAssoCode != "") { maAssoCode = "'" + maAssoCode.split(",").join("','") + "'"; }
            var freightTypeDomain = new C.Domain('freightType', [
                {name: 'cdmFreightTypeId'},
                {name: 'freightTypeCode', display: CSIS.Lang.ID_112280||'费用类别代码', width: 200},
                {name: 'freightTypeName', display: CSIS.Lang.ID_112290||'费用类别名称', width: 200},
                {name: 'freightTypeNameEn', display: CSIS.Lang.ID_112290||'费用类别名称', width: 200},
                {name: 'remark', display: CSIS.Lang.ID_107690||'备注',width:100},
                {name: 'seqNo'},
                {name: 'labelName'}
            ], { domainType:C.DomainType.FOR_COMBO_GRID,
                grid:CSIS.lang=="EN"?'freightTypeCode,freightTypeNameEn,remark':'freightTypeCode,freightTypeName,remark',
                orderBy: 'seqNo'  });

            var extend = "  AND EXISTS(SELECT 1 FROM FreightTypeOrganization C " +
                    "WHERE mtbl.cdmFreightTypeId=C.cdmFreightTypeId AND" +
                    " (RTRIM(C.freightTypeOrganization,'0') like CONCAT(RTRIM('"+companyCode+"','0'),'%') or RTRIM('"+companyCode+"','0') like CONCAT(RTRIM(C.freightTypeOrganization,'0'),'%'))";
            if(companyCode.startWith("0811")){
                extend = " and mtbl.freightTypeCode<>'FY56'  AND EXISTS(SELECT 1 FROM FreightTypeOrganization C " +
                    "WHERE mtbl.cdmFreightTypeId=C.cdmFreightTypeId AND" +
                    " (RTRIM(C.freightTypeOrganization,'0') like CONCAT(RTRIM('"+companyCode+"','0'),'%') or RTRIM('"+companyCode+"','0') like CONCAT(RTRIM(C.freightTypeOrganization,'0'),'%'))";

            }
            if (bndFlag) {
                extend = extend + " AND C.freightTypeDirector = '10'"
            }
            if(companyCode.startWith('080111')){
                extend = "  AND EXISTS(SELECT 1 FROM FreightTypeOrganization C " +
                        "WHERE mtbl.cdmFreightTypeId=C.cdmFreightTypeId AND C.freightTypeOrganization='"+companyCode+"')"
            }
            if(maAssoCode != ""){  extend += " or (C.freightTypeOrganization in ("+maAssoCode+"))";  }
            extend +=")";

            if (currentId == "ff8080815a35be42015a35cb71860001") { //通导模块
                extend += " AND mtbl.freightTypeCode in ('FY67','FY19')"
            }
            freightTypeDomain.getDataSource().setFixFilter({usedFor:'FMM',_extend:extend});   //需要加的扩展条件
            //费用类别的grid
            var freightTypeGrid = {
                type: 'grid',
                labelWidth:130,
                domain: freightTypeDomain,
                searchFields: 'freightTypeName,freightTypeCode,inputCode',    // 检索的字段
                beforeExpand:function(name){
                    var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                    if (invoiceSort == 'FY33') {
                        page.getEditBox().setReadOnly('quantity', false);
                        page.getEditBox().setReadOnly('portCode', false);
                    } else {
                        page.getEditBox().setReadOnly('quantity', true);
                        page.getEditBox().setReadOnly('portCode', true);
                    }
                },
                onSelected: function (rec,name) {
                    //选择了指标类型后，对项目下拉列表赋动态的查询条件
                    freightDomain.getDataSource().clearFilter();
                    freightDomain.getDataSource().addFilter('freightType',rec[0].data.freightTypeCode);
                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","");
                    var labelName = (CSIS.Lang.ID_112030||"发生时间");
                    var newName = rec[0].data.labelName;
                    if(newName!=null&&newName!=""){
                        labelName =  newName;
                    }
                    if(youlunFlag){labelName='发生日期'}
                    var  selectFreightType  = rec[0].data.freightTypeCode;
                    if(companyCode.startWith("91")&&(selectFreightType=='FY62'||selectFreightType=='FY61'))labelName='完工日期'
                        page.getEditBox().getExtField("occurTimeFrom").setFieldLabel(labelName);
                    if(!name.startWith('search.')){    //控制订单号和内部订单号的显示
                        tempFields.put('freightTypeName', CSIS.lang=="EN"?rec[0].data.freightTypeNameEn:rec[0].data.freightTypeName);
                        page.getEditBox().setReadOnly('innerOrder',false);
                        if(youlunFlag){
                            page.getEditBox().setValue('srcOrderType','');
                            page.getEditBox().setValue('innerOrder',"");
                            page.getEditBox().setValue('billNo',"");
                            if(selectFreightType=='FY06'||selectFreightType=='FY41'){
                                setBoxReadOnlyEx(page.getEditBox(),false,'srcOrderType');
                            }else{  setBoxReadOnlyEx(page.getEditBox(),true,'srcOrderType');  }
                            if(selectFreightType=='ZCF')setBoxReadOnlyEx(page.getEditBox(),false,'billNo');else setBoxReadOnlyEx(page.getEditBox(),true,'billNo');
                            if(!daYuanFlag&&companyCode.substring(0,4)!='0811'&&companyCode.substring(0,4)!='1331'){
                                if( (selectFreightType=='FY01'&&(invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'))||
                                        selectFreightType=='FY06'){
                                    page.getEditBox().getExtField('invoiceNo').setValue('')
                                    page.getEditBox().getExtField('invoiceDate').setValue('')
                                    page.getEditBox().getExtField('invoiceCode').setValue('')
                                    setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode');
                                }else{
                                    setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                                }
                            }
                        }else{
                            if(selectFreightType=='FY06'){
                                page.getEditBox().setReadOnly('billNo',true);
                            }else{
                                page.getEditBox().setReadOnly('billNo',false);
                            }
                        }
                        if (rec[0].data.freightTypeCode == 'FY33') {
                            page.getEditBox().getExtField('unit').setComboValue('49','升');
                            page.getEditBox().setReadOnly('quantity', false);
                            page.getEditBox().setReadOnly('portCode', false);
                        } else {
                            page.getEditBox().getExtField('unit').setValue('')
                            page.getEditBox().getExtField('quantity').setValue('')
                            page.getEditBox().getExtField('portCode').setValue('')
                            page.getEditBox().setReadOnly('quantity', true);
                            page.getEditBox().setReadOnly('portCode', true);
                        }

                        if (rec[0].data.freightTypeCode == 'FYR1') {
                            page.getEditBox().setReadOnly('unit', false);
                            page.getEditBox().setReadOnly('quantity', false);
                        } else {
                            page.getEditBox().setReadOnly('unit', true);
                            page.getEditBox().setReadOnly('quantity', true);
                        }
                        if(youlunFlag){
                            if(rec[0].data.freightTypeCode == 'FY69'||rec[0].data.freightTypeCode == 'FYR1'){
                                page.getEditBox().setReadOnly('portCode', false);
                                page.getEditBox().setReadOnly('voyageNo', false);
                            }else{
                                page.getEditBox().getExtField('portCode').setValue('')
                                page.getEditBox().setReadOnly('portCode', true);
                                page.getEditBox().getExtField('voyageNo').setValue('')
                                page.getEditBox().setReadOnly('voyageNo', true);
                            }
                        }
                        //63公司取值的费用类别可能不符所有添加公司判断区分
                        var invoiceSortDetailFlag = !isEmpty(companyCode) && companyCode.substring(0,2)=='63';
                        //68集运费用科目取值与其他公司不同，例：
                        var invoiceSortDetailFlag2 = !isEmpty(companyCode) && companyCode.substring(0,2)=='68';
                        //默认选择的费用科目
                        var invoiceSortDetail = ""
                        if(!companyCode.startWith('1331')&&!companyCode.startWith('0811')){
                            if(selectFreightType=='FY65'){
                                if(invoiceSortDetailFlag){
                                    invoiceSortDetail = "FY65003"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY65003",CSIS.Lang.ID_237270||"油漆费");
                                }else{
                                    if(!youlunFlag){
                                        invoiceSortDetail = "FY65002"
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY65002",CSIS.Lang.ID_139500||"保养油漆费");
                                    }
                                }
                            }else if(selectFreightType=='FY63'){
                                if(invoiceSortDetailFlag){
                                    invoiceSortDetail = "FY63003"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63003",CSIS.Lang.ID_126950||"备件费");
                                }else if(invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY63101"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63101","一般定单");
                                }else{
                                    if(!youlunFlag){
                                        invoiceSortDetail = "FY63002"
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63002",CSIS.Lang.ID_139510||"日常备件费");
                                    }
                                }
                            }else if(selectFreightType=='FY04'){
                                if(invoiceSortDetailFlag||invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY04101"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY04101",CSIS.Lang.ID_140160||"物料费");
                                }else{
                                    if(!youlunFlag){
                                        invoiceSortDetail = "FY04022"
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY04022",CSIS.Lang.ID_139520||"日常维修保养物料费");
                                    }
                                }
                            }else if(selectFreightType=='FY61'){
                                invoiceSortDetail = "FY61001"
                                page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY61001",CSIS.Lang.ID_139530||"厂修费");
                            }else if(selectFreightType=='FY62'){
                                if(invoiceSortDetailFlag||invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY62101"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY62101",CSIS.Lang.ID_237280||"日常航修费");
                                }else{
                                    if(!youlunFlag){
                                        invoiceSortDetail = "FY62001"
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY62001",CSIS.Lang.ID_139540||"机械航修费");
                                    }
                                }
                            }else if(selectFreightType=='FY05'){
                                if(invoiceSortDetailFlag||invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY05011"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY05011",CSIS.Lang.ID_141730||"检验费");
                                }else{
                                    if(!youlunFlag){
                                        invoiceSortDetail = "FY05002"
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY05002",CSIS.Lang.ID_139550||"船级社检验");
                                    }
                                }
                            }else if(selectFreightType=='FY66'){
                                if(!youlunFlag){
                                    invoiceSortDetail = "FY66001"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY66001",CSIS.Lang.ID_139560||"化学品费用");
                                }
                            }else if(selectFreightType=='FY19'){
                                if(!youlunFlag){
                                    invoiceSortDetail = "FY19021"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY19021",CSIS.Lang.ID_139570||"船舶通讯费");
                                }
                            }else if(selectFreightType=='FY67'){
                                if(!youlunFlag){
                                    invoiceSortDetail = "FY67001"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY67001",CSIS.Lang.ID_139570||"通导设备修理费");
                                }
                            }else if(selectFreightType=='FY72'){
                                if(!youlunFlag){
                                    invoiceSortDetail = "FY72001"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY72001",CSIS.Lang.ID_237290||"保养油漆");
                                }
                            }else if(selectFreightType=='FY76'){
                                if(!youlunFlag){
                                    invoiceSortDetail = "FY76002"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY76002",CSIS.Lang.ID_166140||"坞修油漆");
                                }
                            }else if(selectFreightType=='FY73'){
                                if(invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY73001"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY73001",CSIS.Lang.ID_166180||"绑扎件");
                                }
                            }else if(selectFreightType=='FY74'){
                                if(invoiceSortDetailFlag2){
                                    invoiceSortDetail = "FY74001"
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY74001",CSIS.Lang.ID_182780||"劳防用品");
                                }
                            }
                        }
                        if(!isEmpty(invoiceSortDetail)){
                            setGroupSortAndDetailByInvoiceSortDetail(invoiceSortDetail)
                            if(companyCode.startWith("6600")){
                                if(invoiceSortDetail=='FY61001'||invoiceSortDetail=='FY64002')setBoxReadOnlyEx(page.getEditBox(), false, 'isAdvanceFee');
                                else setBoxReadOnlyEx(page.getEditBox(), true, 'isAdvanceFee');
                            }
                        }
                        var vesselCode = page.getEditBox().getExtField('vesselCode').getValue();
                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                        if(!isEmpty(director)){
                            page.getEditBox().getExtField("director").setValue(director);
                        }
                    }
                    if(companyCode.startWith("01")||companyCode.startWith("62")||companyCode.startWith("91")){//增加91开头海峡不默认科目
                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","");
                    }
                    //添加68公司费用费用类别 坞修油漆 保养油漆 对编辑区费用字段的编辑权限
                    if(companyCode.startWith("68") && rec[0].data.freightTypeCode == 'FY76'){
                        page.getEditBox().setReadOnly('dockSelfPolishingQty', false);
                        page.getEditBox().setReadOnly('dockSelfPolishingAmount', false);
                        page.getEditBox().setReadOnly('dockOtherQty', false);
                        page.getEditBox().setReadOnly('dockOtherAmount', false);
                        page.getEditBox().setReadOnly('maintainPrimerQty', true);
                        page.getEditBox().setReadOnly('maintainPrimerAmount', true);
                        page.getEditBox().setReadOnly('maintainOtherQty', true);
                        page.getEditBox().setReadOnly('maintainOtherAmount', true);
                    }
                    if(companyCode.startWith("68") && rec[0].data.freightTypeCode == 'FY72'){
                        page.getEditBox().setReadOnly('dockSelfPolishingQty', true);
                        page.getEditBox().setReadOnly('dockSelfPolishingAmount', true);
                        page.getEditBox().setReadOnly('dockOtherQty', true);
                        page.getEditBox().setReadOnly('dockOtherAmount', true);
                        page.getEditBox().setReadOnly('maintainPrimerQty', false);
                        page.getEditBox().setReadOnly('maintainPrimerAmount', false);
                        page.getEditBox().setReadOnly('maintainOtherQty', false);
                        page.getEditBox().setReadOnly('maintainOtherAmount', false);
                    }
                    if(companyCode.startWith("65")){
                        if (rec[0].data.freightTypeCode=='FYCL'||rec[0].data.freightTypeCode=='FYHW'||
                            rec[0].data.freightTypeCode == 'FYRG'||rec[0].data.freightTypeCode == 'FYHF') {
                            bndFlag = true;
                            page.getEditBox().getExtField("director").setValue("");
                            if (isEmpty(page.getEditBox().getExtField("innerOrder").getValue())) {
                                page.getEditBox().setReadOnly('portCode', false);
                            } else {
                                page.getEditBox().getExtField('portCode').setValue('')
                                page.getEditBox().getExtField('voyageNo').setValue('')
                                page.getEditBox().setReadOnly('portCode', true);
                                page.getEditBox().setReadOnly('voyageNo', true);
                            }
                        } else {
                            bndFlag = false;
                        }
                    }
                    if(companyCode.startWith("0200")){  page.getEditBox().setReadOnly('billNo',true);  }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.freightTypeNameEn : rec[0].data.freightTypeName,
                        value: rec[0].data.freightTypeCode
                    }
                }
            };
            function setGroupSortAndDetailByInvoiceSortDetail(invoiceSortDetail){
                //集团费用类别与大类转码
                if(groupSortMap==null||groupSortDetailMap==null){
                    groupSortMap = codedictMaps['FMM_INV_GROUP_SORT'];
                    groupSortDetailMap = codedictMaps['FMM_INV_GROUP_SORT_DETAIL'];
                }
                C.syncRequest.callAction("list","freight",{freightCode:invoiceSortDetail},
                        function (actionName, domainName, resp) {
                            var result = resp.rows
                            if(!isEmpty(result) && result.length>0){
                                var row = result[0]
                                //选中费用科目默认带出集团费用类别和科目并置灰
                                page.getEditBox().getExtField('groupSort').setComboValue(row.groupSort,groupSortMap[row.groupSort])
                                page.getEditBox().getExtField('groupSortDetail').setComboValue(row.groupSortDetail,groupSortDetailMap[row.groupSortDetail])
                                if(!isEmpty(row.groupSort))
                                    page.getEditBox().setReadOnly('groupSort',true);
                                if(!isEmpty(row.groupSortDetail))
                                    page.getEditBox().setReadOnly('groupSortDetail',true);
                            }
                        })
            }
            //freightTypeRemarkMap yangxl 用于68公司 费用类别备注被 xc td的 在新增发票时 可以复制新增
            var freightTypeRemarkMap = new CSIS.HashMap()
            if (companyCode&&companyCode.startWith("68")) {
                C.ajax.callAction('list','freightType',{_extend:" and remark in('XC','TD','ZF') "},
                    function(action,domainName,resp){
                        if(resp && resp.rows && resp.rows.length>0){
                            for(var i=0;i<resp.rows.length;i++){
                                freightTypeRemarkMap.put(resp.rows[i].freightTypeCode,resp.rows[i].freightTypeCode)
                            }
                        }
                    }
                );
            }

            //费用类别下拉框的查询
            var freightDomain = new C.Domain('freight', [
                {name: 'cdmFreightId'},
                {name: 'seqNo'},
                {name: 'freightCode', display: CSIS.Lang.ID_112300||'费用编码', width: 200},
                {name: 'freightName', display: CSIS.Lang.ID_112310||'费用名称', width: 200},
                {name: 'freightNameEn', display: CSIS.Lang.ID_112310||'费用名称', width: 200},
                {name: 'groupSort', display: CSIS.Lang.ID_122290||'集团费用大类', width: 150},
                {name: 'groupSortDetail', display: CSIS.Lang.ID_122300||'集团费用类别', width: 150},
                {name: 'remark', display: CSIS.Lang.ID_107690||'备注',width:150}
            ], {
                grid: 'freightCode,freightName,remark',
                grid:CSIS.lang=="EN"?'freightCode,freightNameEn,remark':'freightCode,freightName,remark',
                orderBy: 'seqNo'
            });
            var extend2 = "  AND EXISTS(SELECT 1 FROM FreightOrganization K " +
                    "WHERE mtbl.cdmFreightId=K.cdmFreightId AND" +
                    " (RTRIM(K.freightOrganization,'0') like CONCAT(RTRIM('"+companyCode+"','0'),'%') or RTRIM('"+companyCode+"','0') like CONCAT(RTRIM(K.freightOrganization,'0'),'%'))";
            if(companyCode.startWith('080111')){
                extend2 = " AND EXISTS(SELECT 1 FROM FreightOrganization K  " +
                        " WHERE mtbl.cdmFreightId=K.cdmFreightId AND K.freightOrganization ='"+companyCode+"')"
            }
            if(maAssoCode != ""){
                extend2 += " or (K.freightOrganization in ("+maAssoCode+"))";
            }
            extend2 +=")";
            freightDomain.getDataSource().setFixFilter({_extend:extend2});
            //集团费用类别与大类转码
            var groupSortMap ;
            var groupSortDetailMap ;
            //费用科目的显示
            var freightGrid = {
                type: 'grid',
                labelWidth:130,
                domain: freightDomain,
                searchFields: 'freightName,freightCode,inputCode',    // 检索的字段
                beforeExpand:function(name){
                    var invoiceSort="CSISCSISCSISCSISCSIS";
                    if(name.startWith('search.')){
                        invoiceSort = page.getSearchBox().getValue("invoiceSort");
                    }else{
                        invoiceSort = page.getEditBox().getValue("invoiceSort");
                    }
                    freightDomain.getDataSource().clearFilter();
                    if(invoiceSort.length>0){
                        freightDomain.getDataSource().setFixFilter({freightType:invoiceSort,_extend:extend2});
                    } else{
                        freightDomain.getDataSource().setFixFilter({freightType:"1_1_1",_extend:extend2});//为了下拉的数据为空，赋值一个不可能的值
                    }
                },
                onSelected: function (rec,name) {
                    if(!name.startWith('search.')){
                        //集团费用类别与大类转码
                        if(groupSortMap==null||groupSortDetailMap==null){
                            groupSortMap = codedictMaps['FMM_INV_GROUP_SORT'];
                            groupSortDetailMap = codedictMaps['FMM_INV_GROUP_SORT_DETAIL'];
                        }
                        var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                        var orderNo = page.getEditBox().getExtField('innerOrder').getValue()
                        tempFields.put('freightName', CSIS.lang=="EN"?rec[0].data.freightNameEn:rec[0].data.freightName);

                        if (invoiceSort == 'FY33') {
                            page.getEditBox().getExtField('unit').setComboValue('49',CSIS.Lang.ID_155970||'升');
                            C.ajax.callAction('getQuantityAndPort', 'enquireMainMtrVo', {
                                orderNo: orderNo,
                                accountNo: rec[0].data.freightCode
                            }, function (action, domainName, resp) {
                                page.getEditBox().getExtField('quantity').setValue(resp.extend.quantity)
                                page.getEditBox().getExtField('portCode').setValue(resp.extend.portCode)
                            });
                        } else {
                            page.getEditBox().getExtField('unit').setValue('')
                            page.getEditBox().getExtField('quantity').setValue('')
                            page.getEditBox().getExtField('portCode').setValue('')
                        }
                        if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='6600') {  //FY72001  :保养油漆
                            if(rec[0].data.freightCode=='FY72001'){
                                page.getEditBox().setValue("ifJigai",'1');
                            }
                        }
                        if(invoiceSort == 'FY94'&&rec[0].data.freightCode=='FY94004'){
                            page.getEditBox().getExtField('vesselCode').setComboValue('S999','集运共同船舶');
                            tempFields.put('vesselName','集运共同船舶');
                        }
                        if(invoiceSort=='FY01'){
                            if(rec[0].data.freightCode=='FY01001'||rec[0].data.freightCode=='FY01002'){
                                page.getEditBox().setValue('safeFlag',true);
                            }else{
                                page.getEditBox().setValue('safeFlag',false);
                            }
                        }
                        if(youlunFlag||companyCode.startWith("6600")){
                            if((rec[0].data.freightCode=='FY01001')||rec[0].data.freightCode=='FY61001'||invoiceSort=='FY06'||invoiceSort=='FY41'){
                                page.getEditBox().setReadOnly('isAdvanceFee', false);
                            }else{
                                page.getEditBox().getExtField('isAdvanceFee').setValue('')
                                page.getEditBox().setReadOnly('isAdvanceFee', true);
                            }
                        }
                        if(companyCode.startWith("080111")){
                            var falg = true;
                            if(!isEmpty(rec[0].data.freightCode)){
                                C.syncRequest.callAction("list","freight",{freightCode:rec[0].data.freightCode},
                                    function (actionName, domainName, resp) {
                                        var result = resp.rows
                                        if(!isEmpty(result) && result.length>0){
                                            var row = result[0];
                                            if(row.isNonOperating != 1){
                                                falg = false;
                                            }
                                        }
                                });
                            }
                            if(!falg){
                                page.getEditBox().setReadOnly('portCode', false);
                            }else{
                                page.getEditBox().getExtField('portCode').setValue('')
                                page.getEditBox().setReadOnly('portCode', true);
                            }
                        }
                        if(youlunFlag){
                            var invoiceSortDetail = rec[0].data.freightCode;
                            page.getEditBox().setValue('innerOrder',"");
                            page.getEditBox().setValue('billNo',"");
                            if(invoiceSort == 'FY69'&&(invoiceSortDetail=='FY69004'||invoiceSortDetail=='FY69005')||invoiceSort == 'FYR1'){
                                page.getEditBox().setReadOnly('portCode', false);
                                page.getEditBox().setReadOnly('voyageNo', false);
                            }else{
                                page.getEditBox().getExtField('portCode').setValue('')
                                page.getEditBox().setReadOnly('portCode', true);
                                page.getEditBox().getExtField('voyageNo').setValue('')
                                page.getEditBox().setReadOnly('voyageNo', true);
                            }
                            page.getEditBox().setValue('srcOrderType','');
                            if(invoiceSort=='FY06'||invoiceSort=='FY41'||invoiceSort=='ZCF'){
                                setBoxReadOnlyEx(page.getEditBox(),false,'srcOrderType');
                            }else{
                                setBoxReadOnlyEx(page.getEditBox(),true,'srcOrderType');
                            }
                            if(!daYuanFlag){
                                if( (invoiceSort=='FY01'&&(invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'))||
                                        invoiceSort=='FY06'){
                                    if(companyCode.substring(0,4)!='0811'){
                                        page.getEditBox().getExtField('invoiceNo').setValue('')
                                        page.getEditBox().getExtField('invoiceDate').setValue('')
                                        page.getEditBox().getExtField('invoiceCode').setValue('')
                                        setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode');
                                    }
                                }else{
                                    setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                                }
                            }
                        }
                        if(companyCode.startWith("6600")){
                            var invoiceSortDetail = rec[0].data.freightCode;
                            if(invoiceSortDetail=='FY61001'||invoiceSortDetail=='FY64002')setBoxReadOnlyEx(page.getEditBox(), false, 'isAdvanceFee');
                            else setBoxReadOnlyEx(page.getEditBox(), true, 'isAdvanceFee');
                        }

                        //时代航运费用科目关联预付款区域
                        if(companyCode.startWith("080111")){
                            var invoiceSortDetail = rec[0].data.freightCode;
                            if(invoiceSortDetail=='FY64002'||invoiceSortDetail=='FY49022'||invoiceSortDetail=='FY49021'||invoiceSortDetail=='FY64011'){
                                page.getEditBox().getExtField('isAdvanceFee').setValue('');
                                setBoxReadOnlyEx(page.getEditBox(), false, 'isAdvanceFee')
                            }else{
                                page.getEditBox().getExtField('isAdvanceFee').setValue('');
                                setBoxReadOnlyEx(page.getEditBox(), true, 'isAdvanceFee')
                            }
                        }
                        //选中费用科目默认带出集团费用类别和科目并置灰
                        page.getEditBox().getExtField('groupSort').setComboValue(rec[0].data.groupSort,groupSortMap[rec[0].data.groupSort])
                        page.getEditBox().getExtField('groupSortDetail').setComboValue(rec[0].data.groupSortDetail,groupSortDetailMap[rec[0].data.groupSortDetail])
                        if(!isEmpty(rec[0].data.groupSort))
                            page.getEditBox().setReadOnly('groupSort',true);
                        if(!isEmpty(rec[0].data.groupSortDetail))
                            page.getEditBox().setReadOnly('groupSortDetail',true);
                        if(companyCode.startWith("0811")||companyCode.startWith("1331"))page.getEditBox().setValue('safeFlag',false);
                    }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.freightNameEn:rec[0].data.freightName,
                        value: rec[0].data.freightCode
                    }
                }
            };
            var groupSortDomain = new C.Domain('codedict', [
                {name: 'codeId'},
                {name: 'codeValue', display: CSIS.Lang.ID_122210||'集团费用大类代码',width:130},
                {name: 'displayValue', display: CSIS.Lang.ID_122220||'集团费用大类名称',width:130},
                {name: 'displayValueCn', display: CSIS.Lang.ID_122220||'集团费用大类名称',width:130},
                {name: 'sequence'}
            ], { domainType:C.DomainType.FOR_COMBO_GRID,
                grid:'codeValue,displayValue',
                grid:CSIS.lang=="EN"?'codeValue,displayValue':'codeValue,displayValueCn',
                orderBy: 'sequence'});
            var groupSortGrid = {
                type: 'grid',
                labelWidth:130,
                domain: groupSortDomain,
                searchFields: 'codeValue,displayValue',    // 检索的字段
                beforeExpand:function(name){
                    var _groupSordExtend = "AND codeType = 'FMM_INV_GROUP_SORT'";
                    groupSortDomain.getDataSource().loadDataset({_extend:_groupSordExtend});
                },
                onSelected: function (rec,name) {
                    //选择了指标类型后，对项目下拉列表赋动态的查询条件
                    groupSortDetailDomain.getDataSource().clearFilter();
                    if(!name.startWith('search.')){
                        page.getEditBox().getExtField("groupSortDetail").setComboValue("","");
                        tempFields.put('groupSortName', rec[0].data.displayValue);
                    }else{
                        page.getSearchBox().getExtField("groupSortDetail").setComboValue("","");
                    }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.displayValue:rec[0].data.displayValueCn,
                        value: rec[0].data.codeValue
                    }
                }
            };

            //集团费用类别
            var groupSortDetailDomain = new C.Domain('codedict', [
                {name: 'codeId'},
                {name: 'codeValue', display: CSIS.Lang.ID_122230||'集团费用类别代码',width:130},
                {name: 'displayValue', display: CSIS.Lang.ID_122240||'集团费用类别名称',width:130},
                {name: 'displayValueCn', display: CSIS.Lang.ID_122240||'集团费用类别名称',width:130},
                {name: 'sequence'}
            ], {grid:CSIS.lang=="EN"?'codeValue,displayValue':'codeValue,displayValueCn', orderBy: 'sequence'});

            //集团费用类别显示
            var groupSortDetailGrid = {
                type: 'grid',
                labelWidth:130,
                domain: groupSortDetailDomain,
                searchFields: 'codeValue,displayValue',    // 检索的字段
                beforeExpand:function(name){
                    var groupSort="CSISCSISCSISCSISCSIS";
                    if(name.startWith('search.')){
                        groupSort = page.getSearchBox().getValue("groupSort");
                    }else{
                        groupSort = page.getEditBox().getValue("groupSort");
                    }
                    groupSortDetailDomain.getDataSource().clearFilter();
                    var _groupSordDetailExtend = "AND codeType = 'FMM_INV_GROUP_SORT_DETAIL'";
                    if(groupSort.length>0){
                        groupSortDetailDomain.getDataSource().loadDataset({relateValue:groupSort,_extend:_groupSordDetailExtend});
                    } else{
                        groupSortDetailDomain.getDataSource().loadDataset({codeType:"1_1_1"});//为了下拉的数据为空，赋值一个不可能的值
                    }
                },
                onSelected: function (rec,name) {
                    if(!name.startWith('search.')){
                        tempFields.put('groupSortDetailName', rec[0].data.displayValue);
                    }
                    return {
                        display: CSIS.lang=="EN"?rec[0].data.displayValue:rec[0].data.displayValueCn,
                        value: rec[0].data.codeValue
                    }
                }
            };
            var feeContractDomain = new C.Domain('feeContract', [
                {name:'feeContractId'},
                {name:'contractNo',display: CSIS.Lang.ID_139370||'合同编号',length:50},
                {name:'contractName',display: CSIS.Lang.ID_114910||'合同名称',length:200},
                {name:'contactType',display: CSIS.Lang.ID_120580||'合同类型',length:20},
                {name:'signDate',display: CSIS.Lang.ID_139410||'签订日期',type:'date'}
            ], {grid:'contractNo,contractName,contactType,signDate', orderBy: 'feeContractId'});

            //合同grid
            var feeContractGrid = {
                type: 'grid',
                labelWidth:130,
                domain: feeContractDomain,
                searchFields: 'contractNo,contractName',    // 检索的字段
                onSelected: function (rec) {
                    if(!name.startWith('search.')){
                        tempFields.put('contractName', rec[0].data.contractName);
                        page.getEditBox().setValue("feeContractId",rec[0].data.feeContractId);
                    }
                    return {
                        display: rec[0].data.contractName,
                        value: rec[0].data.contractNo
                    }
                }
            };

            var renderCommit = function(value, meta, record){
                if(value==true)  return  CSIS.Lang.ID_107640||"是"
                else return CSIS.Lang.ID_107650||"否"
            };
            var renderIsEnergy = function(value){
                if(value=='1') return  "是"
                else return "否"
            };

            var renderIsTemporary = function(value){
                if(value==true)
                    return  "是"
                else
                    return  "否"
            }
            var jgInnerOrderDomain = new C.Domain('jgInnerOrder', [
                {name:'innerOrderId'},
                {name:'innerOrder',display: CSIS.Lang.ID_139590||'内部订单号',length:80, width:130},
                {name:'projectName',display: CSIS.Lang.ID_109790||'项目名称',length:200,width:200},
                {name:'costBody',display: CSIS.Lang.ID_110230||'所属公司',length:200},
                {name: 'companyName',display:CSIS.Lang.ID_107920||'公司',type:'string',width:130},
                {name: 'vesselCode', display:CSIS.Lang.ID_107220|| '船舶', type: 'string',isNull:false},
                {name:'vesselName',display:CSIS.Lang.ID_107220||'船舶',type:'string',width:100},
                {name:'invoiceSort',display: CSIS.Lang.ID_139600||'费用大类',length:200},
                {name:'year',display: CSIS.Lang.ID_101480||'年份',length:30},
                {name:'isEnergy',display: '是否节能减排',width:150,render:renderIsEnergy},
                {name: 'isTemporary', display: '是否临时',type:'boolean',render:renderIsTemporary,width:80},
                {name:'isPayEnd',display: CSIS.Lang.ID_139610||'支付结束',width:80,render:renderCommit,type:'boolean'}
            ], {grid:'innerOrder,projectName,companyName,vesselName,year,isPayEnd,isEnergy,isTemporary', orderBy: 'innerOrderId'});
            jgInnerOrderDomain.getDataSource().setFixFilter({isPayEnd:0});
            //内部订单号（好像只有在公司开头为0806才会出现，受权限控制）
            var jgInnerOrderGrid = {
                type: 'grid',
                labelWidth:150,
                domain: jgInnerOrderDomain,
                editable:true,
                acceptInputValue:true,
                searchFields: 'innerOrder,projectName,',    // 检索的字段
                beforeExpand: function (name) {
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                    var payer = page.getEditBox().getExtField("payer").getValue();
                    var invoiceSort = page.getEditBox().getExtField("invoiceSort").getValue();
                    invoiceSortSouce=invoiceSort;//原先的
                    var invoiceSortDetail = page.getEditBox().getValue('invoiceSortDetail');
                    var foreStatMonth = page.getEditBox().getValue('foreStatMonth');
                    if(youlunFlag){
                        if(isEmpty(vesselCode)||isEmpty(invoiceSort)||isEmpty(invoiceSortDetail)||isEmpty(foreStatMonth)){
                            Ext.MessageBox.alert('信息',"请先选择船舶、费用类别、费用科目、入账年度");
                            return false;
                        }
                    }
                    jgInnerOrderDomain.getDataSource().clearFilter();
                    if(!youlunFlag) jgInnerOrderDomain.getDataSource().addFilter("costBody",payer);
                    if(!isEmpty(payer)&&(payer.startWith("66")||payer.startWith("0801"))){
                        if(!isEmpty(invoiceSort)&&(invoiceSort=='FY64'||invoiceSort=='FY06')){
                            invoiceSort = 'FY64';
                        }else{
                            invoiceSort = 'FY61';
                        }
                    }
                    if(youlunFlag&&(invoiceSort=='FY06')){
                        jgInnerOrderDomain.getDataSource().loadDataset({year:foreStatMonth,"invoiceSort":invoiceSort,"invoiceSortDetail":invoiceSortDetail,
                        _extend:" and innerOrder not like 'temp%' and  ( mtbl.vesselCode = '"+vesselCode+"'  or mtbl.vesselCodeAsso like  '%"+vesselCode+"%')" });
                    }else if(invoiceSortSouce=="FY56" && companyCode.startWith('66')){
                        //TODO lifangxu 单独选择内部订单号 需要修改当公司为66 费用类别为FY56
                        jgInnerOrderDomain.getDataSource().addFilter("invoiceSortSouce", invoiceSortSouce);
                    } else{
                        jgInnerOrderDomain.getDataSource().addFilter("vesselCode",vesselCode);
                        if(invoiceSort=="FY76"){
                            jgInnerOrderDomain.getDataSource().addFilter("_extend"," and invoiceSort in ('FY76','FY77')");
                        }else{
                            jgInnerOrderDomain.getDataSource().addFilter("invoiceSort",invoiceSort);
                        }
                    }
                },
                onSelected: function (rec,name) {
                    if(rec[0].data.isEnergy=='1'){
                        page.getEditBox().setValue('isEnergy', true);  //是否节能减排
                    }
                    if(rec[0].data.isTemporary=='1' && youlunFlag){ //能源公司用户,同时选中了临时技改单号
                        Ext.MessageBox.alert("系统提示","费用录入不可选用临时技改单号，请至订单界面修改为正式技改单号后再次操作！")
                        return;
                    }
                    return {
                        display: rec[0].data.innerOrder,
                        value: rec[0].data.innerOrder
                    }
                }
            };

            /**
             * 根据内部订单选择控件传回来的信息新增关联信息tab页内容
             */
            var doCreateFmmOpeRelevance =function(rec,pMultiRecords){
                tempRecordLists = []//先把之前添加的记录清除掉
                var records = curDomain.getDataSource().getGridAllRecords();
                curDomain.getDataSource().deleteRecords(records);
                curDomain.getDataSource().clearRecords()
                //控制改变tab页到关联信息页时，不再通过loadDataSet来查询数据
                billNoFlag = true
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                if(invoiceSort == 'FY01'||invoiceSort == 'FY02' ||invoiceSort == 'FY62'||invoiceSort== 'FY63' ||invoiceSort == 'FY64'  ||invoiceSort == 'FY67'||invoiceSort == 'FY61'||invoiceSort == 'FY69' ||invoiceSort == 'FY05' || invoiceSort == 'FY97'){
                    if(invoiceSortDetail == 'FY01003'||invoiceSortDetail == 'FY01004'||invoiceSortDetail == 'FY64001'||
                            invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004'  ||invoiceSort== 'FY63' ){ //备件订购
                        doCreateBJ(rec);//vwFmmSpsPurGridDomain调用后台创建记录newRec，调用PartsOrderSearchView.jsp
                        curDomain = vwFmmSpsPurGridDomain
                        page.getEditBox().getExtField('innerOrder').setComboValue(rec.enquireNo,rec.enquireNo);
                    }else if(invoiceSortDetail == 'FY01002' || invoiceSortDetail == 'FY01005'
                            || invoiceSortDetail == 'FY01007' || invoiceSort == 'FY61' || invoiceSort == 'FY62' ||invoiceSortDetail == 'FY64002' || invoiceSort == 'FY67' ||invoiceSort == 'FY69' ||invoiceSort == 'FY05' || invoiceSort == 'FY97'){ //航修通导订购
                        var shipGuideIds = "";
                        for(var j=0; j<pMultiRecords.length; j++){
                            shipGuideIds+=(pMultiRecords[j].shipGuideId+",")
                            doCreateTD(pMultiRecords[j])  //vwFmmSpsPurGridDomain调用后台创建记录newRec，调用voyageRepairGuideSearchView.jsp
                            if(j==pMultiRecords.length-1){
                                shipGuideIds = shipGuideIds.substr(0,shipGuideIds.length -1);
                            }
                        }
                        curDomain = vwFmmVrmShipGuideQueryDomain2
                        page.getEditBox().getExtField('innerOrder').setComboValue(rec.oddNumber,rec.oddNumber);
                    }else{
                        //修理模块尚在建设
                    }
                }else if(invoiceSort == 'FY04' || (invoiceSort == 'FY28' && companyCode.startWith('65')) || invoiceSort == 'FY33'|| invoiceSort == 'FY65'|| invoiceSort == 'FY66'|| invoiceSort == 'FY58'){//物料订购
                    doCreateWL(rec)   //vwFmmMtrPurGridDomain调用后台创建记录newRec调用PartsOrderMtrSearchView.jsp
                    curDomain = vwFmmMtrPurGridDomain
                    page.getEditBox().getExtField('innerOrder').setComboValue(rec.enquireNo,rec.enquireNo);
                }else {
                    //润料模块尚在建设
                }
            }
            function doCreateBJ(rec){
                var activityMap = getCommonRenderMap('codedict', 'codeValue', 'displayValue', {codeType: 'SPS_APPLY_CONFIRM_TYPE'})
                //根据订购单号，查询船舶库存记录
                C.syncRequest.callAction('getListByEquireMainId','vesselStorage',{Id:rec.enquireMainId},function(a,b,resp){
                    if(resp&&resp.rows&&resp.rows.length>0){
                        var i = 0
                        var exchangeRateMap = new C.HashMap();
                        while(resp.rows[i]){
                            var li =resp.rows[i]
                            var relatedId = li.vesselStorageId
                            var vesselCode = li.vesselCode
                            var vesselName = rec.vesselName
                            var materialNo = li.partsNo
                            var materialName = li.partsName
                            var equipNo = li.equipNo
                            var className = li.equipName
                            var partsInfoId = li.partsInfoId
                            var activityTypeDetail = li.activityTypeDetail
                            var activityDate = li.activityDate
                            var qty = li.qty
                            var supplierCode = rec.supplierCode
                            var supplierName = rec.supplierName
                            var currency = li.currency?li.currency:rec.currency
                            var currencyName = li.currencyName?li.currencyName:rec.currencyName
                            var rate = li.price
                            var relatedAmount = li.totalAmount
                            var relatedAmountWithoutTax = li.feeWithoutTax
                            var feeWithoutTax = li.feeWithoutTax
                            var taxAmount = li.taxFee
                            var cnyFee = li.cnyFee
                            var exchangeRate = li.exchangeRate
                            //计算人民币汇率
                            var cnyExchangeRate = 1;
                            if(li.cnyExchangeRate){
                                cnyExchangeRate = li.cnyExchangeRate
                            }else if(exchangeRateMap.containsKey(currency)){
                                cnyExchangeRate = exchangeRateMap.get(currency);
                            }else{
                                C.syncRequest.callAction('getCurRate','exchangeRate',{currencyFrom:currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            exchangeRateMap.put(currency,resp);
                                            cnyExchangeRate = resp;
                                        });
                            }
                            var invoiceAmount = 0
                            invoiceAmount = li.cnyPrice?li.cnyPrice:li.price?li.price*cnyExchangeRate:0
                            var equipModel = li.partsStyle
                            var cwbtName = li.activityType?activityMap.get(li.activityType):""
                            var auditQty = 0
                            var noAuditQty = li.qty
                            var taxRateName = li.taxRate
                            var cwbtCode = rec.enquireNo///////
                            var auditedFlag = li.auditedFlag
                            var remark=li.remark
                            var portOnlineName=li.portOnlineName
                            var applyConfirmId = li.applyConfirmId;
                            var newRec = {
                                relatedId:relatedId,
                                vesselCode:vesselCode,
                                vesselName:vesselName,
                                materialNo:materialNo,
                                materialName:materialName,
                                equipNo:equipNo,
                                className:className,
                                partsInfoId:partsInfoId,
                                activityTypeDetail:activityTypeDetail,
                                activityDate:activityDate,
                                qty:qty,
                                supplierCode:supplierCode,
                                supplierName:supplierName,
                                currency:currency,
                                currencyName:currencyName,
                                rate:rate,
                                relatedAmount:relatedAmount,
                                relatedAmountWithoutTax:relatedAmountWithoutTax,
                                feeWithoutTax:feeWithoutTax,
                                taxAmount:taxAmount,
                                cnyFee:cnyFee,
                                exchangeRate:exchangeRate,
                                cnyExchangeRate:cnyExchangeRate,
                                invoiceAmount:invoiceAmount,
                                equipModel:equipModel,
                                cwbtName:cwbtName,
                                auditQty:auditQty,
                                noAuditQty:noAuditQty,
                                taxRateName:taxRateName,
                                cwbtCode:cwbtCode,
                                auditedFlag:auditedFlag,
                                remark:remark,
                                portOnlineName:portOnlineName,
                                applyConfirmId : applyConfirmId
                            }
                            vwFmmSpsPurGridDomain.getDataSource().newRecord(newRec);
                            tempRecordLists.push(newRec)
                            i++
                        }
                    }
                })
                //得到记录的detail_id，查询出SPS_VESSEL_STORAGE表的VESSEL_STORAGE_ID来作为relatedId
            }
            function doCreateTD(rec){
                /**航修通导***/
                var newRec = {
                    relatedId:rec.shipGuideId,
                    vesselCode:rec.vesselCode,
                    vesselName:rec.vesselName,
                    cwbtCode:rec.cwbtCode,
                    cwbtName:rec.equipName,
                    materialNo:rec.equipTypeNo,
                    reportDate:rec.reportDate,
                    reportPerson:rec.reportPerson,
                    supplierCode:rec.repairCompany,
                    supplierName:rec.repairCompanyName,
                    activityDate:rec.completeDate,
                    materialName:rec.isCompleted,
                    portName:rec.port,
                    rate:rec.estimateCost,
                    auditedFlag:rec.status,
                    faultStatus:rec.faultStatus,
                    repairContent:rec.repairContent,
                    relatedName:rec.portName,
                    classNo:rec.classNo,
                    className:rec.repairTypeName,
                    companyCode:rec.deptNameShow,
                    vesselCompany:rec.vesselCompany
                }
                vwFmmVrmShipGuideQueryDomain2.getDataSource().newRecord(newRec);
                tempRecordLists.push(newRec)
            }
            function doCreateWL(rec){
                //根据订购单号，查询船舶库存记录
                C.ajax.callAction('getListByEquireMainId','vesselStorageMtr',{Id:rec.enquireMainMtrId},function(a,b,resp){
                    if(resp&&resp.rows&&resp.rows.length>0){
                        Ext.each(resp.rows,function(li){
                            var relatedId = li.vesselStorageMtrId
                            var vesselCode = li.vesselCode
                            var vesselName = rec.vesselName
                            var classNo = li.classNo
                            var className = li.className
                            var materialNo = li.materialNo
                            var materialName = li.materialName
                            var materialInfoId = li.materialInfoId
                            var activityTypeDetail = li.activityTypeDetail
                            var activityDate = li.activityDate
                            var qty = li.qty
                            var supplierCode = rec.supplierCode
                            var supplierName = rec.supplierName
                            var currency = li.currency
                            var currencyName = ""
                            if(currency&&currencyMap.containsKey(currency)){
                                currencyName = currencyMap.get(currency)
                            }else if(currency){
                                C.syncRequest.callAction("list","currency",{currency:currency}, function (actionName, domainName, resp) {
                                    if(resp&&resp.rows&&resp.rows.length>0) {
                                        currencyName = resp.rows[0].currencyName
                                        currencyMap.put(currency,resp.rows[0].currencyName)
                                    }
                                })
                            }
                            var rate = li.price
                            var relatedAmount = li.totalAmount
                            var relatedAmountWithoutTax = li.feeWithoutTax
                            var feeWithoutTax = li.feeWithoutTax
                            var taxAmount = li.taxFee
                            var cnyFee = li.cnyFee
                            var exchangeRate = li.exchangeRate
                            var cnyExchangeRate = li.cnyExchangeRate
                            var invoiceAmount = li.cnyPrice
                            var model = li.model
                            var cwbtName = li.warehouseType
                            var auditQty = li.qty
                            var noAuditQty = 0
                            var taxRateName = li.taxRate
                            var cwbtCode = li.warehouseNo///////
                            var applyConfirmId  = li.applyConfirmMtrId;
                            var newRec = {
                                relatedId:relatedId,
                                vesselCode:vesselCode,
                                vesselName:vesselName,
                                materialNo:materialNo,
                                materialName:materialName,
                                classNo:classNo,
                                className:className,
                                materialInfoId:materialInfoId,
                                activityTypeDetail:activityTypeDetail,
                                activityDate:activityDate,
                                qty:qty,
                                supplierCode:supplierCode,
                                supplierName:supplierName,
                                currency:currency,
                                currencyName:currencyName,
                                rate:rate,
                                relatedAmount:relatedAmount,
                                relatedAmountWithoutTax:relatedAmountWithoutTax,
                                feeWithoutTax:feeWithoutTax,
                                taxAmount:taxAmount,
                                cnyFee:cnyFee,
                                exchangeRate:exchangeRate,
                                cnyExchangeRate:cnyExchangeRate,
                                invoiceAmount:invoiceAmount,
                                model:model,
                                cwbtName:cwbtName,
                                auditQty:auditQty,
                                noAuditQty:noAuditQty,
                                taxRateName:taxRateName,
                                cwbtCode:cwbtCode,
                                applyConfirmId : applyConfirmId
                            }
                            vwFmmMtrPurGridDomain.getDataSource().newRecord(newRec);
                            tempRecordLists.push(newRec)
                        })
                    }
                })
            }
            function  getVoyageNoPopbox(){
                var voyageNoPopBox ={
                    type: 'popbox',
                    acceptInputValue: false,
                    popHeight: 600,
                    popWidth: 1100,
                    popUrl: "../sps/xxxxxxx.jsp",//给一个不可能的页面
                    popResultName: "xxx",
                    readOnly: false,
                    beforeExpand: function (a,b) {
                        var vesselCode = page.getEditBox().getExtField('vesselCode').getValue()
                        var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                        var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                        if(isEmpty(vesselCode)||isEmpty(invoiceSort)||isEmpty(invoiceSortDetail)){
                            Ext.MessageBox.alert('信息',"请选择船舶、费用科目、费用类别");
                            return false;
                        }
                        if(invoiceSort == 'FY69'){
                            b.popUrl = 'fmm/fmmRpt56MainWin.jsp';
                        }else if(invoiceSort == 'FYR1'){
                            b.popUrl = 'fmm/voyageNoRptWin.jsp';
                        }else{
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',"该费用类别无相关航次号，请选择正确的费用类别");
                            return false;
                        }
                        var vessel = page.getEditBox().getExtField('vesselCode').getComboValue();
                        C.context.register('fishpkabc',{vesselCode:vessel.value,vesselName:vessel.display}) ;
                    },
                    onSelected: function (rec, name) {
                        var popBoxResult = C.context.get('popResult')
                        var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                        C.context.unRegister ('popBoxResult')//取消注册的变量
                        C.context.unRegister('popMRecordResult')//取消注册的变量
                        if(popBoxResult){
                            page.getEditBox().getExtField('voyageNo').setValue(popBoxResult.voyageNo);
                        }
                    }
                };
                return  voyageNoPopBox;
            }
            var popUrlPageName = ""
            function getPartsOrderPopBox () {
                //点击订单号弹出框
                var orderPopBox =
                {
                    type: 'popbox',
                    acceptInputValue: false,
                    popHeight: 600,
                    popWidth: 1100,
                    popUrl: "../sps/xxxxxxx.jsp",//给一个不可能的页面
                    popResultName: "xxx",
                    readOnly: false,
                    beforeExpand: function (a,b) {
                        if(a.startWith('search.')) return false
                        debugger;
                        var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue();
                        var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue();
                        var vesselcode = page.getEditBox().getExtField('vesselCode').getValue();
                        if(youlunFlag&&isEmpty(vesselcode)){Ext.MessageBox.alert('信息',"请先选择船舶");  return false;}
                        if((invoiceSort == 'FY01'&&invoiceSortDetail!='FY01012'&&invoiceSortDetail!='FY01013')||invoiceSort == 'FY02' ||invoiceSort == 'FY62'||invoiceSort== 'FY63' ||invoiceSort == 'FY64'||invoiceSort == 'FY67'||invoiceSort == 'FY61'||invoiceSort == 'FY05'||(invoiceSort == 'FY69'&&!youlunFlag)
                                ||invoiceSort == 'FY77'||(!youlunFlag&&invoiceSort == 'FY41')||invoiceSort == 'FY78'||invoiceSort == 'FY79'||invoiceSort == 'FY80'||(companyCode.startWith('08011100') && (invoiceSortDetail == "FY49022"||invoiceSortDetail == "FY49021") )
                                ||invoiceSort == 'FY81'||invoiceSort == 'FY82'||invoiceSort == 'FY83'||invoiceSort == 'FY84'||invoiceSort == 'FY85'||invoiceSort == 'FY86'||invoiceSort == 'FY87'||invoiceSort == 'FY88'||invoiceSort == 'FY13'||invoiceSort == 'FY97'||invoiceSort == 'FY56'){
                            if(invoiceSortDetail == 'FY01003'||invoiceSortDetail == 'FY01004'||invoiceSortDetail == 'FY64001'||invoiceSortDetail == 'FY01008'||
                                    invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004' ||invoiceSort== 'FY63' || invoiceSortDetail == 'FY64011'|| invoiceSortDetail == 'FY56001'){ //备件订购
                                b.popUrl = 'fmm/PartsOrderSearchView.jsp';
                                popUrlPageName = "BJ"
                            }else if((companyCode.startWith('91')&&(invoiceSort == 'FY61'||invoiceSort == 'FY62'||invoiceSort == 'FY67') )){
                                b.popUrl = 'fmm/vendorBillSearchView.jsp';
                            }
                            else  if(( youlunFlag&&(invoiceSortDetail == 'FY01002'||invoiceSortDetail == 'FY01007'||invoiceSortDetail == 'FY01001') )||
                                    (companyCode.startWith('630000') && invoiceSortDetail == "FY64007") ||
                                    (companyCode.startWith('02000000') && (invoiceSortDetail == "FY01001"||invoiceSortDetail == "FY01002"||invoiceSortDetail == "FY01007")) ||
                                    (companyCode.startWith('08011100') && (invoiceSortDetail == "FY64002"||invoiceSortDetail == "FY49022"||invoiceSortDetail == "FY49021"||invoiceSortDetail == "FY64011") )||
                                    invoiceSort == 'FY61'||invoiceSort == 'FY13'||invoiceSort == 'FY62'||invoiceSort == 'FY69'||invoiceSortDetail == 'FY64001'||
                                    invoiceSort == 'FY05'||invoiceSort == 'FY77'||invoiceSort == 'FY41'||invoiceSort == 'FY78'||invoiceSort == 'FY79'||
                                    invoiceSort == 'FY80'||invoiceSort == 'FY67' || invoiceSort == 'FY97'||invoiceSortDetail == 'FY64002'||invoiceSortDetail == 'FY64003'||invoiceSortDetail == 'FY64004' || invoiceSortDetail == 'FY56002' || invoiceSortDetail == 'FY56003'){  //维修
                                if((invoiceSortDetail == 'FY01001'&&youlunFlag)||(companyCode.startWith("6600")&&(invoiceSortDetail=='FY61001'||invoiceSortDetail=='FY64002'))||
                                        (companyCode.startWith('08011100') && (invoiceSortDetail == "FY64002"||invoiceSortDetail == "FY49022"||invoiceSortDetail == "FY49021"||invoiceSortDetail == "FY64011") ) ){
                                    var isAdvanceFee = page.getEditBox().getExtField('isAdvanceFee').getValue();
                                    if(isEmpty(isAdvanceFee)&&companyCode.substring(0,4)!='0811'&&companyCode.substring(0,4)!='1331'){
                                        Ext.MessageBox.alert("提示","请先选择是否预付费",function(){
                                            page.getEditBox().getExtField('isAdvanceFee').focus();
                                        });
                                        return false;
                                    }  }
                                b.popUrl = 'fmm/repairSearchView.jsp';
                            }else if(invoiceSortDetail == 'FY01002'|| invoiceSortDetail == 'FY01005'|| invoiceSortDetail == 'FY01007'){//航修通导订购
                                b.popUrl = 'fmm/voyageRepairGuideSearchView.jsp';
                                popUrlPageName = "TD"
                            }else if(invoiceSort == 'FY81'||invoiceSort == 'FY82'||invoiceSort == 'FY83'||invoiceSort == 'FY84'||invoiceSort == 'FY85'||invoiceSort == 'FY86'||invoiceSort == 'FY87'||invoiceSort == 'FY88'){
                                b.popUrl = 'fmm/tdSearchOrder.jsp';
                            } else if (companyCode.startWith('65')&&(invoiceSortDetail == 'FY64005' || invoiceSortDetail == 'FY64006')) {
                                if (invoiceSortDetail == 'FY64005') {
                                    b.popUrl = 'fmm/PartsOrderSearchView.jsp';
                                    popUrlPageName = "BJ"
                                } else if (invoiceSortDetail == 'FY64006') {
                                    b.popUrl = 'fmm/PartsOrderMtrSearchView.jsp';
                                    popUrlPageName = "WL"
                                }
                            }
                        } else if (companyCode.startWith('65')&&invoiceSort == 'FY28') {
                            b.popUrl = 'fmm/PartsOrderMtrSearchView.jsp';
                            popUrlPageName = "WL"
                        }else if(invoiceSort=='FY04'||invoiceSort =='FY34'||invoiceSort=='FY33'||invoiceSort=='FY65'||invoiceSort=='FY66'
                                ||invoiceSort=='FY72'||invoiceSort=='FY76'||invoiceSort=='FY58'||invoiceSort=='FY73'||invoiceSort=='FY74'
                                ||invoiceSort=='FY75'||invoiceSort=='FY43'||(invoiceSort=='FY16'&&invoiceSortDetail=='FY16006')||
                                (invoiceSort=='FY16'&&invoiceSortDetail=='FY16002'&&youlunFlag) ||
                                (invoiceSort=='FY16'&&invoiceSortDetail=='FY16352')){  //物料订购
                            b.popUrl = 'fmm/PartsOrderMtrSearchView.jsp';
                            popUrlPageName = "WL"
                            if(youlunFlag&&invoiceSortDetail== 'FY04036'){
                                b.popUrl = 'fmm/PartsOrderRecoverSearchView.jsp';
                            }
                        }else if(youlunFlag&&(invoiceSort=='FY41'||invoiceSort=='ZCF'||invoiceSort=='FY06')){
                            var srcOrderType = page.getEditBox().getExtField('srcOrderType').getValue();
                            if(isEmpty(srcOrderType)){
                                Ext.MessageBox.alert("提示","请先选择订单类型",function(){
                                    page.getEditBox().getExtField('srcOrderType').focus();
                                });
                                return false;
                            }else{
                                if(srcOrderType=='0'||srcOrderType=='4'||srcOrderType=='5'||srcOrderType=='6'||srcOrderType=='16'){  //修理
                                    var isAdvanceFee = page.getEditBox().getExtField('isAdvanceFee').getValue();
                                    if(isEmpty(isAdvanceFee)&&srcOrderType!='16'){
                                        Ext.MessageBox.alert("提示","请先选择是否预付费",function(){
                                            page.getEditBox().getExtField('isAdvanceFee').focus();
                                        });
                                        return false;
                                    }
                                    b.popUrl = 'fmm/repairSearchView.jsp';
                                }else if(srcOrderType=='1'||srcOrderType=='3'||srcOrderType=='13'||srcOrderType=='17'||srcOrderType=='11'){//物料
                                    b.popUrl = 'fmm/PartsOrderMtrSearchView.jsp';
                                    popUrlPageName = "WL"
                                }else if(srcOrderType=='2'||srcOrderType=='18'||srcOrderType=='8'){//备件
                                    b.popUrl = 'fmm/PartsOrderSearchView.jsp';
                                    popUrlPageName = "BJ"
                                }
                            }
                        } else if(invoiceSort == 'FY98'){
                            b.popUrl = 'fare/engsaveOrderPopBox.jsp';
                            popUrlPageName = "JNJPF"
                        }else if(invoiceSort == 'FYCL'||invoiceSort == 'FYHF'||invoiceSort == 'FYHW'){ //特运材料费
                            b.popUrl = 'fmm/PartsOrderBndSearchView.jsp';
                            popUrlPageName = "BND"
                        }else if(invoiceSort == 'FYHW'){ //特运货物费
                            b.popUrl = 'fmm/PartsOrderBndHwSearchView.jsp';
                            popUrlPageName = "BNDHW"
                        }else if(invoiceSort == 'FYRG'){ //特运人工费
                            b.popUrl = 'fmm/PartsOrderBndRgSearchView.jsp';
                            popUrlPageName = "BNDRG"
                        }else if(invoiceSort == 'FY03'){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_139630||"润料模块尚在建设，润料费还无法关联信息！");
                            return false;
                        }else if(invoiceSort == 'FY70'){//航海资料
                            b.popUrl = 'fmm/PartsOrderVdmSearchView.jsp';
                            popUrlPageName = "HHZL"
                            validatePageType = "HHZL"
                        }else if (invoiceSort=='FY49') {  //时代计修费
                            if(isEmpty(invoiceSortDetail)){
                                Ext.MessageBox.alert("提示","费用类别选了计修费，但是费用科目未选择，请先选择费用科目然后再选择订单号！",function(){
                                    page.getEditBox().getExtField('invoiceSortDetail').focus();
                                });
                                return false;
                            }
                            if (invoiceSortDetail == 'FY49024') {
                                b.popUrl = 'fmm/PartsOrderSearchView.jsp';
                                popUrlPageName = "BJ"
                            } else if (invoiceSortDetail == 'FY49023' || invoiceSortDetail == 'FY49025') {
                                b.popUrl = 'fmm/PartsOrderMtrSearchView.jsp';
                                popUrlPageName = "WL"
                            }else {
                                b.popUrl = 'fmm/repairSearchView.jsp';
                            }
                        }else {
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_139640||"该费用类别无相关信息");
                            return false;
                        }
                         if (invoiceSort == 'FY05'&&invoiceSortDetail == 'FY05010' &&youlunFlag&&IsYYfee==true) {
                            b.popUrl = 'fmm/PartsOutsideCheck.jsp';//能源公司需求，油公司检验费弹出外部检查列表
                            popUrlPageName = ""
                         }
                        var vessel = page.getEditBox().getExtField('vesselCode').getComboValue();
                        if(vessel){
                            if(youlunFlag){
                                var isAdvanceFee = page.getEditBox().getExtField('isAdvanceFee').getValue();
                                var srcOrderType = page.getEditBox().getExtField('srcOrderType').getValue();
                                var payeeName =  page.getEditBox().getExtField('payee').getComboValue().display
                                var payeeValue =  page.getEditBox().getExtField('payee').getValue()
                                C.context.register('fishpkabc',{vesselCode:vessel.value,vesselName:vessel.display,payee:payeeValue,payeeName:payeeName,
                                    isAdvanceFee:isAdvanceFee,srcOrderType:srcOrderType,invoiceSort:invoiceSort,invoiceSortDetail:invoiceSortDetail}) ;
                            }else{
                                var payeeName =  page.getEditBox().getExtField('payee').getComboValue().display
                                var payeeValue =  page.getEditBox().getExtField('payee').getValue()
                                var innerOrder =  page.getEditBox().getExtField('innerOrder').getValue()
                                C.context.register('fishpkabc',{vesselCode:vessel.value,vesselName:vessel.display,payee:payeeValue,payeeName:payeeName,innerOrder:innerOrder}) ;
                            }
                        }
                        if(invoiceSort=='FY16'&&invoiceSortDetail=='FY16006'){
                            C.context.register('isDefaultOrderType',{orderType:"50",orderTypeName:"劳保用品"});
                        }
                        if(companyCode.startWith("66")){
                            var isAdvanceFee = page.getEditBox().getExtField('isAdvanceFee').getValue();
                            if(invoiceSortDetail == 'FY63001' || invoiceSortDetail == 'FY04021' || invoiceSortDetail == 'FY65001'){
                                C.context.register('isDefaultOrderType',{sortDetail:invoiceSortDetail});
                            }
                            if(invoiceSort=='FY43')C.context.register('isDefaultOrderType',{orderType:"51",orderTypeName:"防疫物品"});
                            if(invoiceSort=='FY04'&&invoiceSortDetail=='FY04107')C.context.register('isDefaultOrderType',{orderType:"17",orderTypeName:"防海盗器材"});
                            if(invoiceSortDetail == 'FY56001'){
                                C.context.register('isDefaultOrderType',{orderType:"V"});
                            }
                            if(invoiceSortDetail == 'FY56002'||invoiceSortDetail == 'FY56003'){
                                C.context.register('isDefaultOrderType',{searchType:"Y"});
                            }
                            if(invoiceSortDetail=='FY61001'||invoiceSortDetail=='FY64002')C.context.register('isDefaultAdvanceFee',{isAdvanceFee:isAdvanceFee});
                        }
                        if(companyCode.startWith('08011100') && (invoiceSortDetail == "FY64002"||invoiceSortDetail == "FY49022"||invoiceSortDetail == "FY49021"||invoiceSortDetail == "FY64011") ){
                            C.context.register('isDefaultAdvanceFee',{isAdvanceFee:isAdvanceFee});
                        }
                        debugger;
                        if(isEmpty(b.popUrl)||"../sps/xxxxxxx.jsp"==b.popUrl){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_139640||"该费用类别无相关信息");
                            return false;
                        }

                        C.context.register('feeType',{invoiceSort:invoiceSort,invoiceSortDetail:invoiceSortDetail,feeInvoiceId: currentRecord!=null?currentRecord.feeInvoiceId:""});
                    },
                    onSelected: function (rec, name) {
                        page.getEditBox().getExtField("occurTimeFrom").setValue(rec.workDate)
                        var erorrMsg="";
                        var popBoxResult = C.context.get('popResult')
                        var pMultiRecords = C.context.get('popMRecordResult')
                        var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                        var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                        console.log(popBoxResult)
                        C.context.unRegister ('popBoxResult')//取消注册的变量
                        C.context.unRegister('popMRecordResult')//取消注册的变量
                        if(popBoxResult){
                            if (popBoxResult.invoiceSortDetail) {
                                page.getEditBox().getExtField('invoiceSortDetail').setComboValue(popBoxResult.invoiceSortDetail,popBoxResult.invoiceSortDetailName);
                            }
                            page.getEditBox().getExtField("vesselCode").setComboValue(popBoxResult.vesselCode,popBoxResult.vesselName);
                            tempFields.put('vesselName', popBoxResult.vesselName);
                            if(!youlunFlag&&!isEmpty(popBoxResult.isSafeprod)){
                                page.getEditBox().getExtField("safeFlag").setValue(popBoxResult.isSafeprod);
                            }
                            //修改付款单位取订单号返回数据的发生时间
                            var enquireMainApplyDate = popBoxResult.applyDate
                            if(isEmpty(enquireMainApplyDate)||youlunFlag){
                                enquireMainApplyDate = new Date()
                            }
                            //主管、船管部门、付款单位的逻辑
                            C.syncRequest.callAction('list','vesselGridVo',{vesselCode:popBoxResult.vesselCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                    var vesselCode = popBoxResult.vesselCode;
                                    if(isEmpty(companyCode)||!(youlunFlag||bndFlag)){   //油运公司
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                    }
                                    tempFields.put('usrName', rs.engineManagerName);
                                    page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                    tempFields.put('departmentName', rs.manageDeptName);
                                    //付款单位
                                    C.syncRequest.callAction('callSpManagement','feeInvoice',{vesselCode:rs.vesselCode,date:enquireMainApplyDate,manageType:'6',currentCompany:'<%=user.getCompanyCode()%>'},
                                            function(action,domainName,resp){
                                                var purchaserValue =  page.getEditBox().getExtField('payer').getComboValue().display
                                                if(resp && resp.rows && resp.rows.length>0){
                                                    var purchaserName =  page.getEditBox().getExtField('payer').getValue();
                                                    if(purchaserName==null || purchaserName==""||youlunFlag){
                                                        page.getEditBox().getExtField('payer').setComboValue(resp.rows[0].MANAGEMENT_CODE,resp.rows[0].MANAGEMENT_NAME);
                                                        tempFields.put('customerName', resp.rows[0].MANAGEMENT_NAME);
                                                    }else{
                                                        if(purchaserName==resp.rows[0].MANAGEMENT_CODE){
                                                            page.getEditBox().getExtField('payer').setComboValue(resp.rows[0].MANAGEMENT_CODE,resp.rows[0].MANAGEMENT_NAME);
                                                            tempFields.put('customerName', resp.rows[0].MANAGEMENT_NAME);
                                                        }else{
                                                            var innerOrder=page.getEditBox().getExtField('innerOrder').getValue();
                                                            if(popBoxResult.enquireNo==innerOrder)
                                                                erorrMsg+="发票付款单位与订单不一致,发票单位：【"+purchaserValue+"】;订单单位：【"+resp.rows[0].MANAGEMENT_NAME+"】!"
                                                        }
                                                    }
                                                }
                                            });
                                }
                            })

                            var payer = page.getEditBox().getExtField('payer').getValue()
                            //订单号
                            if(popBoxResult.enquireNo)
                                page.getEditBox().getExtField('innerOrder').setValue(popBoxResult.enquireNo);
                            //内部订单号
                            //TODO lifangxu
                            if(popBoxResult.innerOrder)
                                page.getEditBox().getExtField('billNo').setValue(popBoxResult.innerOrder);

                            //审计文号
                            if(popBoxResult.auditNo)
                                page.getEditBox().getExtField('auditNo').setValue(popBoxResult.auditNo);
                            //船舶部门
                            if(popBoxResult.dept&&!youlunFlag){
                                page.getEditBox().getExtField("vesselDept").setComboValue(popBoxResult.dept,popBoxResult.deptName);
                            }
                            //航次
                            if (popBoxResult.voyageNo&&page.getEditBox().getExtField("voyageNo")) {
                                page.getEditBox().getExtField("voyageNo").setValue(popBoxResult.voyageNo);
                            }
                            //港口
                            if (popBoxResult.portCode&&page.getEditBox().getExtField("portCode")) {
                                page.getEditBox().getExtField("portCode").setValue(popBoxResult.portCode);
                                if (bndFlag) {
                                    page.getEditBox().setReadOnly('portCode', true);
                                    page.getEditBox().getExtField("portCode").setComboValue(popBoxResult.portCode,popBoxResult.portName);
                                }
                            }
                            //开票单位
                            if(popBoxResult.supplierCode){
                                var salesValue =  page.getEditBox().getExtField('payee').getComboValue().display
                                var salesName =  page.getEditBox().getExtField('payee').getValue()
                                if(salesName==null || salesName==""){
                                    page.getEditBox().getExtField('payee').setComboValue(popBoxResult.supplierCode,popBoxResult.supplierName);
                                    tempFields.put('payeeName', popBoxResult.supplierName);
                                }else{
                                    if(salesName==popBoxResult.supplierCode){
                                        page.getEditBox().getExtField('payee').setComboValue(popBoxResult.supplierCode,popBoxResult.supplierName);
                                        tempFields.put('payeeName', popBoxResult.supplierName);
                                    }else{
                                        var innerOrder=page.getEditBox().getExtField('innerOrder').getValue();
                                        if(popBoxResult.enquireNo==innerOrder)
                                            erorrMsg+="发票开票单位与订单不一致,发票单位：【"+salesValue+"】；订单单位：【"+popBoxResult.supplierName+"】!"
                                    }
                                }
                                //费用流向的逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:popBoxResult.supplierCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        page.getEditBox().getExtField('feeFlow').setComboValue(rs.chargeFlow,rs.chargeFlow);
                                    }
                                })
                            }
                            //币种
                            if(youlunFlag&&(invoiceSort=="FY01"&&invoiceSortDetail=='FY01004')){
                            }else{
                                page.getEditBox().getExtField('currency').setComboValue(popBoxResult.currency,popBoxResult.currencyName);
                                tempFields.put('currencyName', popBoxResult.currencyName);
                                //汇率
                                C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:popBoxResult.currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            page.getEditBox().setValue('exchangeRate',resp);
                                        });
                            }
                            //是否增值税
                            if(!youlunFlag){
                                if(popBoxResult.currency == 'CNY'){
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()
                                }else{
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("0");
                                }
                            }
                            //税率
                            if((popBoxResult.taxRate||popBoxResult.taxRate==0)&&!(youlunFlag&&(invoiceSort=="FY01"&&invoiceSortDetail=='FY01004')) )
                                page.getEditBox().setValue("taxRate",popBoxResult.taxRate.toString());
                            //68公司录入费用类别为物料费、化学品费、保养油漆费、绑扎件、劳防、(物料)其他、坞修油漆费 的时候订单金额不要带过来
                            var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                            if(companyCode&&companyCode.startWith("68")&&(invoiceSort=="FY04"||invoiceSort=="FY66"||invoiceSort=="FY72"||invoiceSort=="FY73"||
                                    invoiceSort=="FY74"||invoiceSort=="FY75"||invoiceSort=="FY76")){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(0);
                                page.getEditBox().getExtField('amountWithoutTax').setValue(0);
                                page.getEditBox().getExtField('dtlTaxAmount').setValue(0);
                                page.getEditBox().getExtField('taxAmount').setValue(0);
                                page.getEditBox().getExtField('dtlAmount').setValue(0);
                                page.getEditBox().getExtField('amount').setValue(0);
                                page.getEditBox().getExtField('baseAmount').setValue(0);
                                page.getEditBox().getExtField('sercAmount').setValue(0);
                            }else if(youlunFlag&&(invoiceSort=="FY01"&&invoiceSortDetail=='FY01004')){
                            }else if(companyCode&&companyCode.startWith("1331")) {
                                //【化运】选择订单号后订单金额不带入
                                page.getEditBox().getExtField('dtlAmountWithoutTax').setValue('');//不含税金额
                                page.getEditBox().getExtField('amountWithoutTax').setValue('');//不含税总金额
                                page.getEditBox().getExtField('dtlTaxAmount').setValue('');//税率
                                page.getEditBox().getExtField('taxAmount').setValue('');//发票总税额
                                page.getEditBox().getExtField('dtlAmount').setValue('');//含税金额
                                page.getEditBox().getExtField('amount').setValue('');//发票总金额
                                page.getEditBox().getExtField('baseAmount').setValue('');//人民币金额
                                page.getEditBox().getExtField('sercAmount').setValue('');//服务费
                            }else{
                                //不含税金额
                                if(popBoxResult.dtlAmountWithoutTax){
                                    page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(popBoxResult.dtlAmountWithoutTax);

                                    var amountWithoutTax = page.getEditBox().getExtField('amountWithoutTax').getValue()
                                    if (isEmpty(amountWithoutTax) || Number(amountWithoutTax) == 0) {
                                        page.getEditBox().getExtField('amountWithoutTax').setValue(popBoxResult.dtlAmountWithoutTax);
                                    }

                                }
                                //税额
                                if(popBoxResult.dtlTaxAmount||popBoxResult.dtlTaxAmount==0){
                                    page.getEditBox().getExtField('dtlTaxAmount').setValue(popBoxResult.dtlTaxAmount);

                                    var taxAmount = page.getEditBox().getExtField('taxAmount').getValue()
                                    if (isEmpty(taxAmount) || Number(taxAmount) == 0) {
                                        page.getEditBox().getExtField('taxAmount').setValue(popBoxResult.dtlTaxAmount);
                                    }
                                }
                                if(popBoxResult.dtlAmount){
                                    page.getEditBox().getExtField('dtlAmount').setValue(popBoxResult.dtlAmount);

                                    var amount = page.getEditBox().getExtField('amount').getValue()
                                    if (isEmpty(amount) || Number(amount) == 0) {
                                        page.getEditBox().getExtField('amount').setValue(popBoxResult.dtlAmount);

                                        var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                                        var currency = page.getEditBox().getValue('currency');
                                        if (currency == 'CNY') {
                                            page.getEditBox().setValue('baseAmount', popBoxResult.dtlAmount);
                                        } else {
                                            page.getEditBox().setValue('baseAmount', (popBoxResult.dtlAmount * exchangeRate).toFixed(2));
                                        }

                                    }


                                }
                                //人民币金额
                                if(popBoxResult.baseAmount)
                                    page.getEditBox().getExtField('baseAmount').setValue(popBoxResult.baseAmount);
                                //服务费
                                if(popBoxResult.record.totalFee&&popBoxResult.record.sreviceRate){
                                    var totalFee = (Number(popBoxResult.record.totalFee)/(Number(popBoxResult.record.sreviceRate)/100+1)).toFixed(2)
                                    var sercAmount = (totalFee*(Number(popBoxResult.record.sreviceRate)/100)).toFixed(2);
                                    page.getEditBox().getExtField('sercAmount').setValue(sercAmount);
                                }else{
                                    page.getEditBox().getExtField('sercAmount').setValue(0);
                                }
                            }
                            if(youlunFlag){
                                if(!(invoiceSort=="FY01"&&invoiceSortDetail=='FY01004')||invoiceSort=="FY04"){
                                    if(popBoxResult.currency == 'CNY'){
                                        page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()
                                    }else{  page.getEditBox().getExtField('ifCanUseTax').setValue("0");}
                                }
                                page.getEditBox().getExtField('billNo').setValue("");
                                if(popBoxResult.innerOrder)page.getEditBox().getExtField('billNo').setValue(popBoxResult.innerOrder);
                                if(popBoxResult.enquireNo)page.getEditBox().setReadOnly('occurTimeFrom', true);
                                if(popBoxResult.billNo)page.getEditBox().getExtField('billNo').setValue(popBoxResult.billNo);
                                var finalBillNo = page.getEditBox().getExtField('billNo').getValue();   //最终的关联号，有可能是从订单号innerOrder中获得，有可能是从关联号billNo中获得
                                //能源公司-根据内部订单号查询对应的是否减排
                                var isEnergy;
                                if(!isEmpty(finalBillNo)) { //非空才做查询是否减排操作
                                    C.syncRequest.callAction('getIsEnergy', 'jgInnerOrder', {innerOrder: finalBillNo},
                                        function (actionName, domainName, resp) {
                                            if (resp.success) {
                                                isEnergy = resp.msg
                                            }
                                        }
                                    )
                                }
                                page.getEditBox().getExtField('isEnergy').setValue(isEnergy);  //设置从关联号查询到的是否减排
                                // page.getEditBox().setReadOnly('isEnergy', true);
                                if(popBoxResult.completionReportId){
                                    page.getEditBox().getExtField('completionReportId').setValue(popBoxResult.completionReportId);
                                }
                            }
                            //获取船管主体(针对天津公司6601订购日期作为入账年度)
                            var manager=""
                            C.syncRequest.callAction('getVesselManager', 'applyMainMtrVo',{vesselCode:popBoxResult.vesselCode}, function (actionName, domainName, resp) {
                                manager=resp.msg;
                            })
                            //备件-选中订单号的订购日期是2017年签收日期是2018年的默认完工日期为2017-12-31入账年度2017签收日期赋值到occurTimeTo
                            var bl = !isEmpty(popBoxResult.orderDate) && !isEmpty(popBoxResult.applyDate) && (Number(new Date(popBoxResult.orderDate).getFullYear())==2017) && (Number(new Date(popBoxResult.applyDate).getFullYear())==2018)?true:false;
                            //天津公司完工日期与订购时间相同
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == "FY04"||invoiceSort == "FY33"||invoiceSort == "FY65"||invoiceSort == "FY66")){
                                if(popBoxResult.orderDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(popBoxResult.orderDate)
                            }else if(invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0,4) && !("66010000" == payer)){
                                page.getEditBox().getExtField('occurTimeFrom').setValue(new Date('2017-12-31'))
                                page.getEditBox().getExtField('occurTimeTo').setValue(popBoxResult.applyDate);
                            }else if(manager.startWith('68')&&popBoxResult.sendVesselDate){
                                page.getEditBox().getExtField('occurTimeFrom').setValue(popBoxResult.sendVesselDate)
                            }else{
                                if(popBoxResult.applyDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(popBoxResult.applyDate)
                            }
                            //天津公司入账年度与订购时间相同，没有订购日期选择当前时间，其他公司签收日期-订购日期-当前时间
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == "FY04"||invoiceSort == "FY33"||invoiceSort == "FY65"||invoiceSort == "FY66")){
                                if(popBoxResult.orderDate){
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(popBoxResult.orderDate));
                                }else{
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }else{
                                if(companyCode!="08011100" || isEmpty(page.getEditBox().getExtField('foreStatMonth').getValue())) {
                                    if (invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0, 4) && !("66010000" == payer)) {
                                        page.getEditBox().getExtField('foreStatMonth').setValue(new Date('2017-12-31'));
                                    } else if (manager.startWith('68') && popBoxResult.sendVesselDate) {
                                        page.getEditBox().getExtField('foreStatMonth').setValue(new Date(popBoxResult.sendVesselDate));
                                    } else if (popBoxResult.applyDate) {
                                        page.getEditBox().getExtField('foreStatMonth').setValue(new Date(popBoxResult.applyDate));
                                    } else if (popBoxResult.orderDate) {
                                        page.getEditBox().getExtField('foreStatMonth').setValue(new Date(popBoxResult.orderDate));
                                    } else {
                                        page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                    }
                                }
                                if(youlunFlag){
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }
                            //
                            if (invoiceSort == 'FY33') {
                                var accountNo = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                                C.ajax.callAction('getQuantityAndPort', 'enquireMainMtrVo', {
                                    orderNo: popBoxResult.enquireNo,
                                    accountNo: accountNo
                                }, function (action, domainName, resp) {
                                    page.getEditBox().getExtField('quantity').setValue(resp.extend.quantity)
                                    page.getEditBox().getExtField('portCode').setValue(resp.extend.portCode)
                                });
                            }
                            //暂时只用备件物料有签收单号与经办人字段赋值逻辑
                            if(!isEmpty(popUrlPageName)&& (popUrlPageName== "WL"||popUrlPageName=="BJ")){
                                if(popUrlPageName== "WL"){
                                    C.syncRequest.callAction("searchSignNo", "enquireMainMtrVo", {vesselCode:popBoxResult.vesselCode,applyNo:popBoxResult.record.applyNo}, function (actionName, domainName, resp) {
                                        if(resp.success){
                                            page.getEditBox().setValue('signNo',resp.msg);
                                        }
                                    });
                                    if(!isEmpty(popBoxResult.record.operatorName)){
                                        page.getEditBox().setValue('confirmUser',popBoxResult.record.operatorName);
                                    }
                                }else if(popUrlPageName=="BJ"){
                                    C.syncRequest.callAction("searchSignNo", "enquireMainVo", {vesselCode:popBoxResult.vesselCode,applyNo:popBoxResult.record.applyNo}, function (actionName, domainName, resp) {
                                        if(resp.success){
                                            page.getEditBox().setValue('signNo',resp.msg);
                                        }
                                    });
                                    C.syncRequest.callAction("searchConfirmUser", "enquireMainVo", {enquireMainId:popBoxResult.record.enquireMainId}, function (actionName, domainName, resp) {
                                        if(resp.success){
                                            page.getEditBox().setValue('confirmUser',resp.msg);
                                        }
                                    });
                                }else{
                                    popUrlPageName = ""
                                }
                            }
                        }
                        if(erorrMsg!="")
                            Ext.MessageBox.alert(CSIS.Lang.ID_162160||"系统提示",erorrMsg);
                    }
                };
                if(!isEmpty(companyCode)&&(companyCode.substring(0,4)=='7101'||companyCode.substring(0,2)=='63')){
                    orderPopBox.editable = true;
                }else{
                    orderPopBox.editable = false;
                }
                return  orderPopBox;
            }

            var salesName = '';
            var purchaserName = '';
            var acceptFlag = false;
            if(!companyCode.startWith('68')&&!companyCode.startWith('65')&&!companyCode.startWith('66')) {
                acceptFlag = true;
            }
            function getTaxInvoiceInfoPopBox () {
                //点击订单号弹出框
                var taxInvoiceInfoPopBox =
                    {
                        type: 'popbox',
                        acceptInputValue: acceptFlag,
                        popHeight: 600,
                        popWidth: 1300,
                        popUrl: "../fmm/taxInvoiceInfoWin.jsp",
                        popResultName: "xxx",
                        readOnly: false,
                        beforeExpand: function (a,b) {
                            if(a.startWith('search.')) return false
                            // if(!companyCode.startWith('68')&&!companyCode.startWith('65')&&!companyCode.startWith('66')&&!companyCode.startWith('0802')&&!companyCode.startWith('0200')&&!companyCode.startWith('0801')) {
                            if(!companyCode.startWith('1331')&&!companyCode.startWith('68')&&!companyCode.startWith('65')&&!companyCode.startWith('66')&&!companyCode.startWith('0802')&&!companyCode.startWith('0200')&&!companyCode.startWith('0801')) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","未对接税控系统，不能选择发票！");
                                return false;
                            }
                            var invoiceNo = page.getEditBox().getExtField('invoiceNo').getValue();
                            var invoiceCode = page.getEditBox().getExtField('invoiceCode').getValue();
                            var payerName = page.getEditBox().getExtField('payer').rawValue;
                            var payeeName = page.getEditBox().getExtField('payee').rawValue;
                            var payer = page.getEditBox().getExtField('payer').getValue();
                            C.context.register('popParam',{payer:payer,invoiceNo:invoiceNo,invoiceCode:invoiceCode,payerName:payerName,payeeName:payeeName,invoicePage:page});
                        },
                        onSelected: function (rec, name) {
                            var popBoxResult = C.context.get('popResult')
                            C.context.unRegister ('popResult')//取消注册的变量
                            if (popBoxResult) {
                                salesName = popBoxResult.salesName;
                                salesName = replacePayeeName(salesName);

                                purchaserName = popBoxResult.purchaserName;
                                purchaserName = replacePayeeName(purchaserName);

                                page.getEditBox().getExtField('invoiceNo').setValue(popBoxResult.invoiceNo);
                                page.getEditBox().getExtField('invoiceCode').setValue(popBoxResult.invoiceCode);
                                page.getEditBox().getExtField('invoiceDate').setValue(popBoxResult.invoiceDate);
                                page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(popBoxResult.dtlAmountWithoutTax);
                                page.getEditBox().getExtField('amountWithoutTax').setValue(popBoxResult.amountWithoutTax);
                                page.getEditBox().getExtField('dtlTaxAmount').setValue(popBoxResult.dtlTaxAmount);
                                page.getEditBox().getExtField('taxAmount').setValue(popBoxResult.taxAmount);
                                page.getEditBox().getExtField('dtlAmount').setValue(popBoxResult.dtlAmount);
                                page.getEditBox().getExtField('amount').setValue(popBoxResult.amount);
                                page.getEditBox().getExtField("currency").setComboValue("CNY","人民币");
                                tempFields.put('currencyName', "人民币");
                                page.getEditBox().getExtField('ifCanUseTax').setValue(popBoxResult.invoiceType);
                                page.getEditBox().getExtField('baseAmount').setValue(popBoxResult.dtlAmount);
                                var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                                var taxAmount = Number(popBoxResult.taxAmount);//有可能编辑区计算未赋值导致计算税率失败
                                page.getEditBox().getExtField("taxRate").setValue((accDiv(taxAmount, amountWithoutTax).toFixed(2)));
                                page.getEditBox().getExtField('taxCheckState').setValue(popBoxResult.taxCheckState);
                                page.getEditBox().getExtField('scScanId').setValue(popBoxResult.scScanId);
                                if (popBoxResult.taxCheckState == '0') {
                                    setBoxReadOnlyEx(page.getEditBox(),true,"amount,taxAmount,amountWithoutTax,invoiceCode,invoiceDate,currency,ifCanUseTax,taxRate");
                                }
                            }
                        }
                    };
                return  taxInvoiceInfoPopBox;
            }

            var directorDomain = new C.Domain('vwVopVesselOfficers', [
                {name: 'vesselManagerId'},
                {name: 'manager'},
                {name: 'managerName'},
                {name: 'displayName'}
            ], { grid:'displayName',orderBy:'role'});

            //主管的grid
            var directorList = {
                type: 'list',
                domain: directorDomain,
                valueField:'managerName',
                displayField:'managerName',
                autoLoadData:false,
                beforeExpand:function(name){
                    var vesselCode = page.getEditBox().getValue('vesselCode');
                    var definitionDate = page.getEditBox().getValue('occurTimeFrom')
                    directorDomain.getDataSource().clearFilter();
                    if (isEmpty(vesselCode)) {
                        directorDomain.getDataSource().setFixFilter({'vesselCode.eq':'SSMPSSMPSSMP'});
                    } else {
                        if (bndFlag) {
                            var voyageNo = page.getEditBox().getValue('voyageNo')
                            directorDomain.getDataSource().setFixFilter({'vesselShoreInd.eq':'D','vesselCode.eq':vesselCode,'role.eq':voyageNo});
                        } else {
                            directorDomain.getDataSource().setFixFilter({'vesselShoreInd.eq':'S','vesselCode.eq':vesselCode,
                                'definitionDateFrom.to':definitionDate,'definitionDateTo.from':definitionDate});
                        }
                    }

                    directorDomain.getDataSource().load();//该处一定要调用load方法而不是loadDataset
                },
                onSelected: function (rec) {
                    tempFields.put('usrName', rec.managerName);
                }
            }
            function taxRateDyOnSelected (rec){
                var dyTaxRate = Number(rec.codeValue);
                var equipBillRmb = Number(page.getEditBox().getValue('equipBillRmb'));
                page.getEditBox().setValue('dyAmount',accAdd(accMul(equipBillRmb, dyTaxRate),equipBillRmb));
            }
            function taxRateOnSelected(rec){
                tempFields.put('taxRateName',rec.displayValueCn);
                if(isNeedChange&&(rec.displayValueCn!='其他'&&rec.codeValue!='其他')){
                    var taxRate = Number(rec.codeValue);
                    var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                    var taxAmount = amountWithoutTax * taxRate;
                    page.getEditBox().setValue('taxAmount', taxAmount);
                    page.getEditBox().setValue('amount', amountWithoutTax + taxAmount);
                    var dtlTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                    var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                    var dtlTaxAmount = taxRate * dtlTax;
                    page.getEditBox().setValue('dtlTaxAmount', dtlTaxAmount);
                    page.getEditBox().setValue('dtlAmount', dtlTaxAmount + dtlTax);
                    page.getEditBox().setValue('baseAmount', (dtlTaxAmount + dtlTax) * exchangeRate);
                }
            }
            function payeeBeforeExpand(name){
                var invoiceSort = page.getEditBox().getValue('invoiceSort')
                if(!name.startWith('search.') && invoiceSort){
                    if("FY63"==invoiceSort){
                        C.context.register("comboPopValues",{showNode:'SPS'});//供应商类型
                    }
                    if("FY04"==invoiceSort||"FY66"==invoiceSort||"FY72"==invoiceSort||"FY73"==invoiceSort||"FY74"==invoiceSort){
                        C.context.register("comboPopValues",{showNode:'MTR'});//供应商类型
                    }
                    C.context.register('isEditContext',true);
                }
            }
            function payeeOnSelected(rec,name){
                page.getEditBox().getExtField('feeFlow').setComboValue(rec.chargeFlow,rec.chargeFlow);
            }
            //点选编辑区的付款单位选中事件
            function payerSelected(rec,name){
                var officeCode = rec.officeCode;
                if(youlunFlag)return false;
                if(officeCode=='08010000'||officeCode=='08011200'||officeCode=='08015300'){
                    page.getEditBox().setValue('safeFlag',false);
                    page.getEditBox().getExtField('safeFlag').setDisabled(true);
                }else{
                    page.getEditBox().getExtField('safeFlag').setDisabled(false);
                }
            }
            function safeItemOnSelected(rec,list,name){
                if(!name.startWith('search.') ) tempFields.put('safeItemName',rec.displayValueCn);
            }

            function srcOrderTypeSelect(rec,list,name){
                if(!name.startWith('search.') ){
                    page.getEditBox().setValue('innerOrder',"");
                    page.getEditBox().setValue('billNo',"");
                    var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue();
                    var srcOrderType = rec.codeValue;
                    if(!isEmpty(invoiceSort)&&invoiceSort=='FY06'){
                        if(srcOrderType=='1'||srcOrderType=='2'||srcOrderType=='3'||srcOrderType=='13')setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                        else setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode');
                    }
                }
            }

            var stateRender = function(value, meta, record){
                if(value == ''||value.trim() == '1')  return (CSIS.Lang.ID_115590||'新增');
                if(value.trim() == '3')  return (CSIS.Lang.ID_119620||'未审核')
                if(value.trim() == '4') return (CSIS.Lang.ID_110270||'已审核')
                if(value.trim() == '5') return (CSIS.Lang.ID_115630||'已付款')
                if(value.trim() == '6') return ('退票')
                if(value.trim() == '7') return ('取消退票')
            }

            var strikeRender = function(value, meta, record){
                if(value == '0'|| value == '') return CSIS.Lang.ID_107650||'否'
                if(value == '1') return CSIS.Lang.ID_107640||'是'
            }

            var oaSatausRender= function(value, meta, record){
                if(value == '0' || value == '') return '未发送'
                if(value == '1') return '已发送'
            }

            var sendAuditIndRender = function(value, meta, record){
                if(value == ''|| value == '') return CSIS.Lang.ID_107650||'否'
                if(value == '1') return CSIS.Lang.ID_107640||'是'
            }
            var taxCheckStateRender = function(value, meta, record){
                if(value == '0') return '合规';
                if(value == '1') return '失控';
                if(value == '2') return '作废';
                if(value == '3') return '红冲';
                if(value == '4') return '异常';
            }
            var renderDirector = function(value, meta, record){
                return record.get('usrName') ? record.get('usrName') : record.get('director');
            };
            var beforeOfficeExtend = function(rec,name){
                C.context.register('calibreParameter',{searchType:'KG'});
            }
            var srcOrderTypeDomain=getCodedictDomain('FMM_JG_ORDER_TYPE');
            var srcOrderTypeExpand = function(name){
                if(!name.startWith('search.')&&youlunFlag){
                    var invoiceSort = page.getEditBox().getValue('invoiceSort');
                    srcOrderTypeDomain.getDataSource().loadDataset({relateValue:invoiceSort});
                }
            }
            var isDoubtRender = function(value, meta, record){
                if(value == ''||value.trim() == '0')  return "";
                if(value.trim() == '1')  return "确认疑问账单"
                if(value.trim() == '2') return "取消疑问账单"
                if(value.trim() == '3') return "解决疑问账单"
            }
            var ytFromRender = function(value, meta, record){
                if(value == ''||value.trim() == '0')  return "手工录入";
                if(value.trim() == '1')  return "远通接口"
                if(value.trim() == '2') return "网页接口"
            }
            var fapiao = 'feeContractId,baseAmountWithoutTax,foreStatMonth,invoiceSort,invoiceSortDetail,innerOrder,vesselCode,director,department,vesselDept,payer,payee,feeFlow,' +
                    'invoiceDesc,invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,ifJigai,' +
                    'amountWithoutTax,taxRate,taxAmount,amount,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                    'occurTimeFrom,occurTimeTo,isFixedAsset,safeFlag,safeItem,remark,groupSort,groupSortDetail,miscAmount,' +
                    'sercAmount,otherAmount,billNo,unit,quantity,portCode,voyageNo,isEnergy,billQuote,confirmUser,signNo,isAdvanceFee,auditNo,' +
                    'excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo,transType';
            var fapiao1 = 'feeContractId,baseAmountWithoutTax,foreStatMonth,invoiceSort,invoiceSortDetail,innerOrder,vesselCode,director,department,vesselDept,payer,payee,feeFlow,' +
                    'invoiceDesc,invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,ifJigai,' +
                    'amountWithoutTax,taxRate,taxAmount,amount,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                    'occurTimeFrom,occurTimeTo,isFixedAsset,safeFlag,safeItem,remark,groupSort,groupSortDetail,miscAmount,' +
                    'sercAmount,otherAmount,billNo,zfCurrency,zfExchangeRate,unit,quantity,portCode,isEnergy,billQuote,' +
                    'confirmUser,signNo,auditNo,excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo';
            var fapiao2 = 'feeContractId,baseAmountWithoutTax,foreStatMonth,invoiceSort,invoiceSortDetail,innerOrder,vesselCode,director,department,vesselDept,payer,payee,feeFlow,' +
                    'invoiceDesc,invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,ifJigai,' +
                    'amountWithoutTax,taxRate,taxAmount,amount,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                    'occurTimeFrom,occurTimeTo,isFixedAsset,safeFlag,safeItem,remark,groupSort,groupSortDetail,miscAmount,sercAmount,otherAmount,billNo,unit,quantity,portCode,isEnergy,billQuote,' +
                    'confirmUser,signNo,auditNo,dockSelfPolishingQty,dockSelfPolishingAmount,dockOtherQty,dockOtherAmount,maintainPrimerQty,maintainPrimerAmount,maintainOtherQty,maintainOtherAmount,' +
                    'dockOrMaintainTotalAmount,excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo,equipBillQuote,equipBillCurrency';
            var fapiaoOpposite;
            if(!isEmpty(companyCode)&&companyCode.substring(0,2)=='62') {
                fapiaoOpposite = fapiao1;
            }else if(!isEmpty(companyCode)&&companyCode.startWith('68')){
                fapiaoOpposite = fapiao2;
            }else if(!isEmpty(companyCode)&&companyCode.startWith('080111')){
                fapiaoOpposite = 'feeContractId,baseAmountWithoutTax,foreStatMonth,invoiceSort,invoiceSortDetail,innerOrder,vesselCode,director,department,vesselDept,payer,payee,feeFlow,' +
                    'invoiceDesc,invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,ifJigai,' +
                    'amountWithoutTax,taxRate,taxAmount,amount,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                    'occurTimeFrom,occurTimeTo,isDirtRecordInvoice,safeFlag,safeItem,remark,groupSort,groupSortDetail,miscAmount,' +
                    'sercAmount,otherAmount,billNo,unit,quantity,portCode,voyageNo,isEnergy,billQuote,confirmUser,signNo,isAdvanceFee,auditNo,' +
                    'excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo,transType,isFixedAsset';
            } else{
                fapiaoOpposite = fapiao;
            }


            var transTypEditor = {
                type: 'popbox',
                id:'transType',
                name:'transType',
                valueField: 'paymentNo',
                displayField: 'paymentNo',
                popHeight: Ext.getBody().getHeight() * 0.8,
                popWidth: Ext.getBody().getWidth() * 0.8 ,
                popUrl:"../fmm/transTypeBox.jsp",
                popResultName: "paymentNo",
                beforeExpand: function (name){
                    if(isEmpty(page.getEditBox().getExtField("payer").getValue()) || isEmpty(page.getEditBox().getExtField("payee").getValue())){
                        Ext.MessageBox.alert("系统提示","请输入付款单位和开票单位！");
                        return false;
                    }
                    C.context.register('payer',page.getEditBox().getExtField("payer").getValue());
                    C.context.register('payee',page.getEditBox().getExtField("payee").getValue());
                },
                onSelected: function (rec, name) {
                }
            };

            /**航次挂港的港口grid*/
            var voportDomain = new C.Domain('voyPort', [
                {name: 'voyPortId'},
                {name: 'vesselVoyId'},
                {name: 'portId'},
                {name: 'vesselCode', display: "船舶code", width: 120},
                {name: 'vesselName', display: "船舶名称", width: 200},
                {name: 'voyageNo', display: "航次", isNull: false, width: 80},
                {name: 'portCode', display: "港口代码", isNull: false, width: 80},
                {name: 'portName', display: "港口名称", isNull: false, width: 80},
                {name: 'portNameEn', display: "港口英文名称", isNull: false, width: 80},
                {name: 'seqNo', display: "港序", width: 80},
            ], {
                grid: 'vesselName,voyageNo,portCode,portName,seqNo',
                orderBy: 'begainDt desc,arriPortDt desc,seqNo desc'
            });
            var portGrid = {
                type: 'grid',
                domain: voportDomain,
                acceptInputValue: false,
                likeModel: 'a',
                searchFields: 'portCode,portName,portNameEn,seqNo',    // 检索的字段
                beforeExpand: function (name) {
                    var vesselCode = "CSISISISISISIS";
                    if (name.startWith('search.')) {
                        vesselCode = page.getSearchBox().getValue("vesselCode");
                    } else {
                        vesselCode = page.getEditBox().getExtField("vesselCode").getValue()
                    }
                    if (vesselCode == null || vesselCode == "") {
                        vesselCode = "CSISISISISISIS";
                    }
                    //为指标类型下拉列表赋初始查询条件
                    voportDomain.getDataSource().loadDataset({
                        vesselCode: vesselCode,
                        limit: 100
                    });
                },
                onSelected: function (rec, name) {
                    tempFields.put('portName', CSIS.lang == "EN" ? rec[0].data.portNameEn : rec[0].data.portName);
                    page.getEditBox().getExtField("voyageNo").setValue(rec[0].data.voyageNo);

                    return {
                        display: CSIS.lang == "EN" ? rec[0].data.portNameEn : rec[0].data.portName,
                        value: rec[0].data.portCode
                    }
                }
            };

            if (!bndFlag) {
                portGrid = getPortGrid();
            }

            var innerOrderRender = function (value, meta, record) {
                meta.style = 'white-space:normal;word-break:break-all;vertical-align: middle;';
                //linkPath 代表找到跳转链接，空就不添加超链接
                var innerOrde = value;
                var linkPath = innerOrdeLink(innerOrde,record,companyCode);
                if(linkPath){
                    return  "<a href=\"javascript:openPageLink(" + linkPath + ");\">" + value + "</a>  ";
                }else{
                    return value;
                }
            };

            var orderNoRender = function (value, meta, record) {
                meta.style = 'white-space:normal;word-break:break-all;vertical-align: middle;';
                //linkPath 代表找到跳转链接，空就不添加超链接
                var innerOrde = value;
                var linkPath = orderNoLink(innerOrde,companyCode);
                if(linkPath){
                    return  "<a href=\"javascript:openPageLink(" + linkPath + ");\">" + value + "</a>  ";
                }else{
                    return value;
                }
            };

            var feeInvoiceDomain1 = new C.Domain('feeInvoice', [
                {name:'feeInvoiceId'},
                {name:'feeContractId',type:'hide'},
                {name:'payeeName',display: CSIS.Lang.ID_124380||'开票单位名称',length:200,width:200},
                {name:'invoiceNo',display: CSIS.Lang.ID_112440||'发票号',isNull:false,type:'comboPopBox',editor:getTaxInvoiceInfoPopBox(),width:200,length:companyCode.startWith('68')?200:(companyCode.startWith('66')?20:30)},
                {name:'invoiceCode',display: CSIS.Lang.ID_112450||'发票代码',length:20,width:90},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',editor:currencyGrid,length:10,isNull:false},
                {name:'currencyName',display: CSIS.Lang.ID_107510||'币种',width:50},
                {name:'zfCurrency',display: CSIS.Lang.ID_237300||'杂费币种',editor:zfCurrencyGrid,length:10,isNull:false},
                {name:'zfCurrencyName',display: CSIS.Lang.ID_237300||'杂费币种',width:50},
                {name:'invoiceDate',display: CSIS.Lang.ID_112420||'发票日期',type:'date',format:'Y-m-d',isNull:false,maxValue:new Date()},
                {name:'groupSort',display: CSIS.Lang.ID_122290||'集团费用大类',type:'comboGrid',editor:groupSortGrid},
                {name:'groupSortName',display: CSIS.Lang.ID_122290||'集团费用大类',type:'string',width:100},
                {name:'groupSortDetail',display: CSIS.Lang.ID_122300||'集团费用类别',type:'comboGrid',editor:groupSortDetailGrid},
                {name:'groupSortDetailName',display: CSIS.Lang.ID_122300||'集团费用类别',type:'string',width:100},
                {name:'invoiceSort',display: CSIS.Lang.ID_112470||'费用类别',type:'comboGrid',editor:freightTypeGrid,isNull:false,length:5},
                {name:'freightTypeName',display: CSIS.Lang.ID_112470||'费用类别',type:'string',width:100},
                {name:'invoiceSortDetail',display: CSIS.Lang.ID_112480||'费用科目',type:'comboGrid',editor:freightGrid,isNull:false,length:10},
                {name:'freightName',display: CSIS.Lang.ID_112480||'费用科目',type:'string'},
                {name:'vesselDept',display: CSIS.Lang.ID_124390||'船舶部门',editor: getCodedictList3('PMS_VESSEL_DEPARTMENT'),type: 'comboList'},
                {name:'invoiceDesc',display: CSIS.Lang.ID_124400||'费用摘要',type:'string',length:100,width:220},
                {name:'ifCanUseTax',display: CSIS.Lang.ID_112540||'是否增值税',type: 'combo',valueList:[
                    {label:CSIS.Lang.ID_237310||'普通发票',value:'0'},
                    {label:CSIS.Lang.ID_237320||'增值税专用发票',value:'1'},
                    {label:CSIS.Lang.ID_237330||'增值税普通发票',value:'2'},
                    {label:CSIS.Lang.ID_237331||'增值税电子普通发票',value:'3'},
                    {label:CSIS.Lang.ID_237332||'增值税普通发票(卷式)',value:'4'},
                    {label:'增值税专用电子发票',value:'5'},
                    {label:'电子发票(增值税专用发票)',value:'6'},
                    {label:'电子发票(增值税普通发票)',value:'7'}
                ]} ,
                {name:'taxFlag',display: CSIS.Lang.ID_124420||'费用含税标志',length:10},
                {name:'taxRate',display: CSIS.Lang.ID_107600||'税率',type:'comboList',editor:getCodedictList3('FMM_RATE_TAX_OTHER',null,null,taxRateOnSelected),length:12},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率',type:'string'},
                {name:'amountWithoutTax',display: CSIS.Lang.ID_237350||'不含税总金额(元)',type:'number',isNull:false,length:12},
                {name:'taxAmount',display: CSIS.Lang.ID_232330||'发票总税额(元)',type:'number',isNull:false,length:12},
                {name:'vesselCode',display: CSIS.Lang.ID_100050||'船舶',type:'comboGrid',editor:getVesselGrid(null,tempFields,null,vesselGridOnSelected),isNull:false,length:10},
                {name:'vesselName',display: CSIS.Lang.ID_100050||'船舶',type:'string',width:100},
                {name:'exchangeRate',display: CSIS.Lang.ID_107520||'汇率',length:18,width:70,isNull:false},
                {name:'zfExchangeRate',display: CSIS.Lang.ID_237360||'杂费汇率',length:18,width:70,isNull:false},
                {name:'baseAmount',display: CSIS.Lang.ID_112580||'人民币金额(元)',type:'number',isNull:false,length:12},
                {name:'gatheringLinkman',display: CSIS.Lang.ID_124430||'收款联系人',readOnly:{edit:true},length:50},
                {name:'futurePrice',display: CSIS.Lang.ID_124440||'预估金额',readOnly:{edit:true},type:'number',length:12},
                {name:'billQuote',display: CSIS.Lang.ID_124450||'账单报价',type:'number',readOnly:{edit:true},length:12},
                {name:'occurTimeFrom',display: CSIS.Lang.ID_123940||'完工日期',type:'date',format:'Y-m-d',maxValue:new Date()},
                {name:'occurTimeTo',display: CSIS.Lang.ID_124460||'发生时间到',type:'hide',format:'Y-m-d'},
                {name:'payee',display: CSIS.Lang.ID_112500||'开票单位',type:'comboPopBox',editor:getCustomerPopBox('GYS',tempFields,'payeeName',payeeBeforeExpand,payeeOnSelected),isNull:false},
                {name:'payer',display: CSIS.Lang.ID_107240||'付款单位',width:170,type:'comboPopBox',editor:getOfficePopBox(tempFields,'customerName',null,payerSelected),isNull:false},
                {name:'payerSearch',display: CSIS.Lang.ID_107240||'付款单位',type:'comboPopBox',editor:getOfficePopBoxChecked(beforeOfficeExtend)},
                {name:'customerName',display: CSIS.Lang.ID_107240||'付款单位',type:"string",width:170},
                {name:'signNo',display: CSIS.Lang.ID_107780||'签收单号',readOnly:{edit:true}},
                {name:'signer',display: CSIS.Lang.ID_107790||'签收人',readOnly:{edit:true}},
                {name:'signDate',display: CSIS.Lang.ID_115710||'签收日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'isSendFin',display: CSIS.Lang.ID_112640||'是否已送财务',type:'boolean'},
                {name:'sendFinDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'sendSapDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'confirmUser',display: CSIS.Lang.ID_124480||'经办人',readOnly:{edit:true}},
                {name:'projectName',display: CSIS.Lang.ID_124490||'是否挂单',readOnly:{edit:true}},
                {name:'billNo',display: CSIS.Lang.ID_139590||'内部订单号',type:'comboGrid',editor:jgInnerOrderGrid},
                {name:'confirmDate',display: CSIS.Lang.ID_124510||'制单日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'invoiceStatus',display:CSIS.Lang.ID_112610||'发票状态',readOnly:{edit:true},type:'combo',editor:{
                    type:'list',
                    domain: currencyDomain,
                    searchChecked:true ,
                    allText:'全选',
                    addAllSelector: true,
                    valueField:"value",
                    displayField:"label",
                    store:CSIS.Ext.createValueListStore([
                        {label: '新增', value: '1'},
                        {label: '未审核', value: '3'},
                        {label: '已审核', value: '4'},
                        {label: '已付款', value: '5'},
                        {label: '退票', value: '6'},
                        {label: '取消退票', value: '7'}])
                },render:stateRender,width:70},
                {name:'sendStatus',display: CSIS.Lang.ID_107540||'发送状态',readOnly:{edit:true},length:1},
                {name:'ifSendFi',display: CSIS.Lang.ID_124520||'是否发送财务',type:'boolean'},
                {name:'paymentNoticeId',display: CSIS.Lang.ID_230090||'付款单ID'},
                {name:'ifAudit',display: CSIS.Lang.ID_119740||'是否审核',type:'boolean',readOnly:{edit:true}},
                {name:'amount',display: CSIS.Lang.ID_112530||'发票总金额(元)',type:'number',isNull:false,length:12},
                {name:'dtlAmount',display: CSIS.Lang.ID_232190||'含税金额(元)',type:'number',isNull:false,readOnly:true,length:12},
                {name:'dtlTaxAmount',display: CSIS.Lang.ID_107610||'税额(元)',type:'number',isNull:false,length:12},
                {name:'dtlAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额(元)',type:'number',isNull:false,length:12},
                {name:'innerOrderSearch',display: CSIS.Lang.ID_110210||'订单号',type:'string'},
                {name:'innerOrder',display: CSIS.Lang.ID_110210||'订单号',type:'comboPopBox',editor:getPartsOrderPopBox(),width:200,render: innerOrderRender},
                {name:'orderNo',display: CSIS.Lang.ID_124540||'付款单号',readOnly:{edit:true},width:100,render: orderNoRender},
                {name:'contractNo',display: CSIS.Lang.ID_124550||'合同',type:'comboGrid',editor:feeContractGrid},
                {name:'contractName',display: CSIS.Lang.ID_124550||'合同'},
                {name:'isCommit',display: CSIS.Lang.ID_124560||'是否提交',type:'boolean',readOnly:{edit:true}},
                {name:'checkAmount',display: CSIS.Lang.ID_139380||'核定金额(元)',type:'number',readOnly:{edit:true},length:12},
                {name:'inputUser',display: CSIS.Lang.ID_112670||'录入人',readOnly:{edit:true},width:70},
                {name:'inputDate',display: CSIS.Lang.ID_112660||'录入日期',type:'date',format:'Y-m-d',readOnly:{edit:true},width:100},
                {name:'foreStatMonth',display: CSIS.Lang.ID_124570||'入账年度',type:'date',format:'Y',isNull:false,width:55},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string',length:200,width:200},
                {name:'ifJigai',display: CSIS.Lang.ID_124580||'库存管理',type:'boolean'},
                {name:'isFixedAsset',display: CSIS.Lang.ID_130730||'固定资产',type:'boolean'},
                {name:'safeFlag',display: CSIS.Lang.ID_124590||'是否属安全费',type:'boolean'},
                {name:'safeItem',display: CSIS.Lang.ID_124591||'安全费类别',type:'comboList',editor:getCodedictList3('FMM_SAFE_ITEM','displayValueCn',null,safeItemOnSelected,true),length:20},
                {name:'safeItemName',display: CSIS.Lang.ID_124591||'安全费类别',width:90,type:'string'},
                {name:'director',display: CSIS.Lang.ID_124600||'主管',width:60,type:'comboList',editor:directorList,render:renderDirector},
                {name:'usrName',display: CSIS.Lang.ID_124600||'主管',width:60,type:'string'},
                {name:'departmentName',display: CSIS.Lang.ID_124610||'船管部门',width:110,type:'string',length:100},
                {name:'department', display: CSIS.Lang.ID_124610||'船管部门', type:'comboTree', editor:fix_officeTree},
                {name:'feeFlow',display: CSIS.Lang.ID_107020||'费用流向',type:'comboList',editor:getCodedictList3('FMM_CHARGE_FLOW','displayValueCn'),isNull:false,length:20},
                {name:'feeFlowName',display: CSIS.Lang.ID_107020||'费用流向',width:60,type:'string'},
                {name:'isStrike',display: CSIS.Lang.ID_124640||'是否负冲销',type:'string',render:strikeRender},
                {name:'fiReceiveDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d'},
                {name:'finishDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d'},
                {name:'baseAmountWithoutTax',display: CSIS.Lang.ID_232410||'人民币不含税金额(元)',type:'hide'},
                {name:'isWarn',display: CSIS.Lang.ID_102680||'是否超期',type: 'combo',
                    valueList: [ {label: CSIS.Lang.ID_225650||'<全部>', value: '全部'},
                        {label: CSIS.Lang.ID_124660||'已超期', value: '1'},
                        {label: CSIS.Lang.ID_124670||'未超期', value: '0'}]   },
                {name:'miscAmount',display: CSIS.Lang.ID_232420||'运杂费(元)',type:'number',isNull:true,length:12},
                {name:'sercAmount',display: CSIS.Lang.ID_232430||'服务费(元)',type:'number',isNull:true,length:12},
                {name:'otherAmount',display: CSIS.Lang.ID_232440||'其他费用(元)',type:'number',isNull:true,length:12},
                {name: 'unit',display: CSIS.Lang.ID_166640||'单位',type: 'comboList',editor: getCodedictList3('CDM_VOC_UNIT'),readOnly: {edit: true}},
                {name: 'unitName',display: CSIS.Lang.ID_166640||'单位'},
                {name: 'quantity', display: CSIS.Lang.ID_111650||'数量', type: 'number', length: 12, readOnly: {edit: true}},
                {name: 'price', display: CSIS.Lang.ID_107420||'单价', type: 'number', length: 12, readOnly: {edit: true}},
				{name: 'portCode', display: CSIS.Lang.ID_139650||'签收港口',type:'comboGrid',editor:portGrid, length: 20, readOnly: {edit: true}},
				{name: 'voyageNo', display: CSIS.Lang.ID_107230||'航次', type: 'string', readOnly: {edit: true}},
                {name:'equipUse',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,type:'hide'},
                {name:'equipUse1',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_EUQIP_KIND'),type:'hide'},
                {name:'equipUse2',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_LPA_KIND'),type:'hide'},
                {name:'equipUse3',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_MTR_KIND'),type:'hide'},
                {name:'equipUse4',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_PAINT_KIND'),type:'hide'},
                {name:'equip',display: CSIS.Lang.ID_139670||'设备数量',isNull:true,length:12},
                {name:'payeeOrder',display: CSIS.Lang.ID_139680||'供应商订单号',isNull:true},
                {name:'ownOrderNo',display: CSIS.Lang.ID_261300||'PPM项目号',type:"string"},
                {name:'purchaseDate',display: CSIS.Lang.ID_139700||'采购日期',isNull:true,type:'date',format:'Y-m-d'},
                {name:'equipBillQuote',display: CSIS.Lang.ID_139710||'订单金额',isNull:true,length:12,type:"hide"},
                {name:'equipBillCurrency',display: CSIS.Lang.ID_139720||'订单币种',isNull:true,type:"hide"},
                {name:'equipBillCurrencyName',display: CSIS.Lang.ID_139720||'订单币种'},
                {name:'equipBillRate',display: CSIS.Lang.ID_107520||'汇率',isNull:true,length:18},
                {name:'equipBillRmb',display: CSIS.Lang.ID_139730||'折合人民币金额',isNull:true,length:12},
                {name:'invoiceSortDy',display: CSIS.Lang.ID_112470||'费用类别'},
                {name:'invoiceSortDetailDy',display: CSIS.Lang.ID_112480||'费用科目'},
                {name: 'dyTaxRate', display: CSIS.Lang.ID_107600||'税率',type:'comboList',editor:getCodedictList3('FMM_TAX_RATE',null,null,taxRateDyOnSelected),length:14},
                {name: 'dyAmount', display: CSIS.Lang.ID_139740|| '税后金额',type:'number',length:14},
                {name :'sendAuditInd',display: CSIS.Lang.ID_139750||'是否送审计',type:'String',render:sendAuditIndRender},
                {name :'sendAuditUser',display: CSIS.Lang.ID_139760||'送审人员',type:'String'},
                {name :'sendAuditDate',display: CSIS.Lang.ID_139810||'送审时间',type:'date',format:'Y-m-d'},
                {name:'isEnergy',display: CSIS.Lang.ID_237370||'是否节能减排',type:'boolean'},
                {name:'auditNo',display: CSIS.Lang.ID_221320||'审计文号',type:'String'},
                {name :'sendFiDate',display: CSIS.Lang.ID_139780||'送财务时间',type:'date',format:'Y-m-d'},
                {name:'dockSelfPolishingQty',display:CSIS.Lang.ID_168870||'坞修自抛光数量',type:'number',format:'0.000',length:13,width:100},
                {name:'dockSelfPolishingAmount',display:CSIS.Lang.ID_168880||'坞修自抛光金额',type:'number',format:'0.00',length:14,width:100},
                {name:'dockOtherQty',display:CSIS.Lang.ID_168890||'坞修其他数量',type:'number',format:'0.000',length:13,width:100},
                {name:'dockOtherAmount',display:CSIS.Lang.ID_168900||'坞修其他金额',type:'number',format:'0.00',length:14,width:100},
                {name:'maintainPrimerQty',display:CSIS.Lang.ID_168910||'保养底漆数量',type:'number',format:'0.000',length:13,width:100},
                {name:'maintainPrimerAmount',display:CSIS.Lang.ID_168920||'保养底漆金额',type:'number',format:'0.00',length:14,width:100},
                {name:'maintainOtherQty',display:CSIS.Lang.ID_168930||'保养其他数量',type:'number',format:'0.000',length:13,width:100},
                {name:'maintainOtherAmount',display:CSIS.Lang.ID_168940||'保养其他金额',type:'number',format:'0.00',length:14,width:100},
                {name:'品种数量',display:CSIS.Lang.ID_168940||'保养其他金额',type:'number',format:'0.00',length:14,width:100},
                {name:'dockOrMaintainTotalAmount',display:CSIS.Lang.ID_168820||'品种数量',type:'number',format:'0.000',length:13,readOnly: {edit: true}},
                {name:'updatedDtmLoc',display: CSIS.Lang.ID_110830||'更新日期',type:'date',format:'Y-m-d H:i:s',width:150},
                {name:'excessReason',display: CSIS.Lang.ID_251940||'理由',type:'string',width:120},
                {name:'isAdvanceFee',display: '是否预付费',type: (companyCode.substring(0,4)=='6600' || companyCode.startWith('08011100') || companyCode.startWith('6300'))?'combo':'hide',valueList:[
                    {label:'否',value:'0'},
                    {label:'是',value:'1'},
                ]},
                {name:'transType',display: CSIS.Lang.ID_806400||'关联预付款单号',type:companyCode.startWith('08011100')?'comboPopBox':'hide',editor:transTypEditor,width:120},
                {name:'taxCheckState',display: CSIS.Lang.ID_251920||'查验标记',type:'string',render:taxCheckStateRender,readOnly: {edit: false}},
                {name:'invoiceCheckCode',display: CSIS.Lang.ID_251930||'校验码后6位',type:'string',emptyText: "-请输入校验码,普票、电子普票、卷式普票必填"},
                {name:'scScanId',display: '关联税务发票表ID',type:'hide'},
                {name:'isDoubt',display: CSIS.Lang.ID_251870||'是否疑问账单',type: 'combo',valueList:[
                    {label:'全部',value:''},{label:'确认疑问账单',value:'1'},{label:"取消疑问账单",value:'2'},{label:"解决疑问账单",value:'3'}
                ],render:isDoubtRender,width:100},
                {name:'bmsId',display: '关联bmsid',type: 'hide'},
                {name:'bmsDelReason',display: 'BMS退回原因',type: 'string'},
                {name:'compType',display: '是否非商务费用',type: 'hide'},
                {name:'oaStatus',display: '发送OA状态',type:'string',render:oaSatausRender},
                {name:'isDirtRecordInvoice',display: '智能船舶项目费用',type:'combo',editable:false,valueList:[
                    {label:'是',value:'1'},
                    {label:'否',value:'0'}
                ]}
            ], {search:'invoiceNo,invoiceDate.from,invoiceDate.to,payerSearch,innerOrderSearch,payee.eq,vesselCode,inputDate.from,inputDate.to,' +
            'department,groupSort,groupSortDetail,invoiceSort,invoiceSortDetail,occurTimeFrom.from,occurTimeFrom.to,feeFlow,safeFlag,finishDate.from,finishDate.to,' +
            'isWarn,currency,billNo,fiReceiveDate.from,fiReceiveDate.to,ifCanUseTax,invoiceStatus,ifJigai,isFixedAsset,amount,inputUser,orderNo,isEnergy,isDoubt',
                searchSuffix: {
                    from: CSIS.Lang.ID_227770||'从',
                    to: CSIS.Lang.ID_227780||'到'
                },
                searchConfig:{payee:{columnWidth:CSIS.lang=="EN"?1/4:2/6},payerSearch:{columnWidth:CSIS.lang=="EN"?1/4:2/6},orderNo:{columnWidth:CSIS.lang=="EN"?1/4:2/6}},
                grid:'foreStatMonth,freightTypeName,freightName,vesselName,innerOrder,invoiceNo,currencyName,dtlAmountWithoutTax,taxRateName,dtlTaxAmount,dtlAmount,sercAmount,miscAmount,baseAmount,baseAmountWithoutTax,' +
                    'amountWithoutTax,taxAmount,amount,invoiceDate,occurTimeFrom,orderNo,projectName,director,departmentName,customerName,' +
                    'payeeName,feeFlowName,invoiceCode,invoiceDesc,currencyName,exchangeRate,ifCanUseTax,billNo,ifJigai,isFixedAsset,safeFlag,safeItemName,remark,'+
                    'invoiceStatus,sendFinDate,inputUser,inputDate,confirmDate,sendSapDate,contractName,isStrike,sendAuditInd,sendAuditDate,' +
                    'sendFiDate,groupSortName,groupSortDetailName,voyageNo,portCode,updatedDtmLoc,isDoubt,oaStatus',
                editTab: CSIS.lang=="EN"?{
                    'invoice info':fapiaoOpposite,
                    'Payment status':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,signer,signDate,' +
                    'isCommit,checkAmount,inputUser,inputDate,sendSapDate',
                    'order item':'invoiceSortDy,invoiceSortDetailDy,equipUse,equipUse1,equipUse2,equipUse3,equipUse4,equip,payeeOrder,purchaseDate,equipBillQuote,'+
                    'equipBillCurrency,equipBillRate,equipBillRmb,dyTaxRate,dyAmount'
                }:{
                    '发票信息':fapiaoOpposite,
                    '付款状态':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,signer,signDate,' +
                    'isCommit,checkAmount,inputUser,inputDate,sendSapDate'
                },
                editConfig:{payee:{columnWidth:0.5},payer:{columnWidth:0.5},invoiceDesc:{columnWidth:0.75},remark:{columnWidth:0.5},invoiceNo:{readOnly:true},excessReason:{columnWidth:0.5}},
                orderBy: 'createdDtmLoc desc,invoiceNo,inputDate desc'});

            if (!isEmpty(companyCode)&&companyCode.substring(0,2)=='68') {
                feeInvoiceDomain1.getDataSource({pageSize:200})
            }
            // 由于油运的发票信息编辑栏输入顺序不一样，所以另外弄一个domain在页面初始化的时候判断改用哪个domain
            var domain2EditStr = 'feeContractId,baseAmountWithoutTax,foreStatMonth,vesselCode,invoiceSort,invoiceSortDetail,srcOrderType,innerOrder,billNo,department,director,payer,payee,feeFlow,' +
                'invoiceDesc,invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,taxRate,' +
                'amountWithoutTax,taxAmount,amount,isAmountFirst,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                'occurTimeFrom,occurTimeTo,ifJigai,isFixedAsset,safeFlag,safeItem,isFreight,remark,groupSort,groupSortDetail,miscAmount,sercAmount,otherAmount,unit,quantity,isEnergy,billQuote,confirmUser,signNo,voyageNo,portCode,isAdvanceFee,excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo,completionReportId,' +
                'passengers,voyageName,flightNumber,billPrice,taxSubtotal,serviceCharge,backAmount';
            var feeInvoiceDomain2 = new C.Domain('feeInvoice', [
                {name:'feeInvoiceId'},
                {name:'feeContractId',type:'hide'},
                {name:'payeeName',display: CSIS.Lang.ID_124380||'开票单位名称',length:200,width:200},
                {name:'invoiceNo',display: CSIS.Lang.ID_112440||'发票号',type:'comboPopBox',editor:getTaxInvoiceInfoPopBox(),length:30,width:110},
                {name:'invoiceCode',display: CSIS.Lang.ID_112450||'发票代码',length:30,width:90},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',editor:currencyGrid,length:10,isNull:false},
                {name:'currencyName',display: CSIS.Lang.ID_107510||'币种',width:50},
                {name:'invoiceDate',display: CSIS.Lang.ID_112420||'发票日期',type:'date',format:'Y-m-d'},
                {name:'groupSort',display: CSIS.Lang.ID_122290||'集团费用大类',type:'comboGrid',editor:groupSortGrid},
                {name:'groupSortName',display: CSIS.Lang.ID_122290||'集团费用大类',type:'string',width:100},
                {name:'groupSortDetail',display: CSIS.Lang.ID_122300||'集团费用类别',type:'comboGrid',editor:groupSortDetailGrid},
                {name:'groupSortDetailName',display: CSIS.Lang.ID_122300||'集团费用类别',type:'string',width:100},
                {name:'invoiceSort',display: CSIS.Lang.ID_112470||'费用类别',type:'comboGrid',editor:freightTypeGrid,isNull:false,length:5},
                {name:'freightTypeName',display: CSIS.Lang.ID_112470||'费用类别',type:'string',width:100},
                {name:'invoiceSortDetail',display: CSIS.Lang.ID_112480||'费用科目',type:'comboGrid',editor:freightGrid,isNull:false,length:10},
                {name:'freightName',display: CSIS.Lang.ID_112480||'费用科目',type:'string'},
                {name:'vesselDept',display: CSIS.Lang.ID_124390||'船舶部门',editor: getCodedictList3('PMS_VESSEL_DEPARTMENT'),type: 'comboList'},
                {name:'invoiceDesc',display: CSIS.Lang.ID_124400||'费用摘要',type:'string',length:100,width:220},
                {name:'ifCanUseTax',display: CSIS.Lang.ID_112540||'是否增值税',type: 'combo',valueList:[
                    {label:CSIS.Lang.ID_237310||'普通发票',value:'0'},
                    {label:CSIS.Lang.ID_237320||'增值税专用发票',value:'1'},
                    {label:CSIS.Lang.ID_237330||'增值税普通发票',value:'2'},
                    {label:CSIS.Lang.ID_237331||'增值税普通发票(电子)',value:'3'},
                    {label:CSIS.Lang.ID_237332||'增值税普通发票(卷式)',value:'4'},
                    {label:'增值税专用电子发票',value:'5'},
                    {label:'电子发票(增值税专用发票)',value:'6'},
                    {label:'电子发票(增值税普通发票)',value:'7'}
                ]} ,
                {name:'isAmountFirst',display: CSIS.Lang.ID_124410||'是否先输入含税金额',type:'boolean',length:10},
                {name:'taxFlag',display: CSIS.Lang.ID_124420||'费用含税标志',length:10},
                {name:'taxRate',display: CSIS.Lang.ID_107600||'税率',type:'comboList',editor:getCodedictList3('FMM_RATE_TAX_OTHER',null,null,taxRateOnSelected),length:12},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率',type:'string'},
                {name:'amountWithoutTax',display: CSIS.Lang.ID_237350||'不含税总金额(元)',type:'number',isNull:false,length:12},
                {name:'taxAmount',display: CSIS.Lang.ID_232330||'发票总税额(元)',type:'number',isNull:false,length:12},
                {name:'vesselCode',display: CSIS.Lang.ID_100050||'船舶',type:'comboGrid',editor:getVesselGrid(null,tempFields,null,vesselGridOnSelected),isNull:false,length:10},
                {name:'vesselName',display: CSIS.Lang.ID_100050||'船舶',type:'string',width:100},
                {name:'exchangeRate',display: CSIS.Lang.ID_107520||'汇率',length:18,width:70,isNull:false},
                {name:'baseAmount',display: CSIS.Lang.ID_112580||'人民币金额(元)',type:'number',isNull:false,length:12},
                {name:'gatheringLinkman',display: CSIS.Lang.ID_124430||'收款联系人',readOnly:{edit:true},length:50},
                {name:'futurePrice',display: CSIS.Lang.ID_124440||'预估金额',readOnly:{edit:true},type:'number',length:12},
                {name:'billQuote',display: CSIS.Lang.ID_124450||'账单报价',type:'number',readOnly:{edit:true},length:12},
                {name:'occurTimeFrom',display:'发生日期',type:'date',format:'Y-m-d'},
                {name:'occurTimeTo',display: '发生时间到',type:'date',format:'Y-m-d'},
                {name:'payee',display: CSIS.Lang.ID_112500||'开票单位',type:'comboPopBox',editor:getCustomerPopBox('GYS',tempFields,'payeeName',null,payeeOnSelected),isNull:false},
                {name:'payer',display: CSIS.Lang.ID_107240||'付款单位',width:170,type:'comboPopBox',editor:getOfficePopBox(tempFields,'customerName'),isNull:false},
                {name:'payerSearch',display: CSIS.Lang.ID_107240||'付款单位',type:'comboPopBox',editor:getOfficePopBoxChecked(beforeOfficeExtend)},
                {name:'customerName',display: CSIS.Lang.ID_107240||'付款单位',type:"string",width:170},
                {name:'signNo',display: CSIS.Lang.ID_107780||'签收单号'},
                {name:'signer',display: CSIS.Lang.ID_107790||'签收人',readOnly:{edit:true}},
                {name:'signDate',display: CSIS.Lang.ID_115710||'签收日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'isSendFin',display: CSIS.Lang.ID_112640||'是否已送财务',type:'boolean'},
                {name:'sendFinDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'confirmUser',display: CSIS.Lang.ID_124480||'经办人',readOnly:{edit:true}},
                {name:'projectName',display: CSIS.Lang.ID_124490||'是否挂单',readOnly:{edit:true}},
                {name:'billNo',display: '关联单号',type:'comboGrid',editor:jgInnerOrderGrid},
                {name:'billNoName',display:'关联单号',type:"string"},
                {name:'confirmDate',display: CSIS.Lang.ID_124510||'制单日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'invoiceStatus',display: CSIS.Lang.ID_112610||'发票状态',readOnly:{edit:true},type:'comboList',editor:{
                    type:'list',
                    domain: currencyDomain,
                    searchChecked:true ,
                    allText:CSIS.Lang.ID_107180||'全选',
                    addAllSelector: true,
                    valueField:"value",
                    displayField:"label",
                    store:CSIS.Ext.createValueListStore([
                        {label: CSIS.Lang.ID_115590||'新增', value: '1'},
                        {label: CSIS.Lang.ID_119620||'未审核', value: '3'},
                        {label: CSIS.Lang.ID_110270||'已审核', value: '4'},
                        {label: CSIS.Lang.ID_115630||'已付款', value: '5'}])
                },render:stateRender,width:70},
                {name:'sendStatus',display: CSIS.Lang.ID_107540||'发送状态',readOnly:{edit:true},length:1},
                {name:'ifSendFi',display: CSIS.Lang.ID_124520||'是否发送财务',type:'boolean'},
                {name:'paymentNoticeId',display: CSIS.Lang.ID_230090||'付款单ID'},
                {name:'ifAudit',display: CSIS.Lang.ID_119740||'是否审核',type:'boolean',readOnly:{edit:true}},
                {name:'amount',display: CSIS.Lang.ID_112530||'发票总金额(元)',type:'number',isNull:false,length:12},
                {name:'dtlAmount',display: CSIS.Lang.ID_232190||'含税金额(元)',type:'number',isNull:false,readOnly:true,length:12},
                {name:'dtlTaxAmount',display: CSIS.Lang.ID_107610||'税额(元)',type:'number',isNull:false,length:12},
                {name:'dtlAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额(元)',type:'number',isNull:false,length:12},
                {name:'innerOrderSearch',display: CSIS.Lang.ID_110210||'订单号',type:'string'},
                {name:'innerOrder',display: CSIS.Lang.ID_110210||'订单号',type:'comboPopBox',editor:getPartsOrderPopBox(),render: innerOrderRender},
                {name:'orderNo',display: CSIS.Lang.ID_124540||'付款单号',readOnly:{edit:true},width:100,render: orderNoRender},
                {name:'contractNo',display: CSIS.Lang.ID_124550||'合同',type:'comboGrid',editor:feeContractGrid},
                {name:'contractName',display: CSIS.Lang.ID_124550||'合同'},
                {name:'isCommit',display: CSIS.Lang.ID_124560||'是否提交',type:'boolean',readOnly:{edit:true}},
                {name:'checkAmount',display: CSIS.Lang.ID_139380||'核定金额(元)',type:'number',readOnly:{edit:true},length:12},
                {name:'inputUser',display: CSIS.Lang.ID_112670||'录入人',readOnly:{edit:true},width:70},
                {name:'inputDate',display: CSIS.Lang.ID_112660||'录入日期',type:'date',format:'Y-m-d',readOnly:{edit:true},width:100},
                {name:'foreStatMonth',display: CSIS.Lang.ID_124570||'入账年度',type:'date',format:'Y',isNull:false,width:55},
                {name:'remark',display: '运费摘要',type:'string',length:200,width:200},
                {name:'ifJigai',display: CSIS.Lang.ID_124580||'库存管理',type:'boolean'},
                {name:'safeFlag',display: CSIS.Lang.ID_124590||'是否属安全费',type:'boolean'},
                {name:'safeItem',display: CSIS.Lang.ID_124591||'安全费类别',type:'comboList',editor:getCodedictList3('FMM_SAFE_ITEM','displayValueCn',null,safeItemOnSelected,true),length:20},
                {name:'safeItemName',display: CSIS.Lang.ID_124591||'安全费类别',width:90,type:'string'},
                {name:'director',display: CSIS.Lang.ID_124600||'主管',width:60,type:'comboList',editor:directorList,render:renderDirector},
                {name:'usrName',display: CSIS.Lang.ID_124600||'主管',width:60,type:'string'},
                {name:'departmentName',display: CSIS.Lang.ID_124610||'船管部门',width:110,type:'string',length:100},
                {name:'department', display: CSIS.Lang.ID_124610||'船管部门', type:'comboTree', editor:fix_officeTree},
                {name:'feeFlow',display: CSIS.Lang.ID_107020||'费用流向',type:'comboList',editor:getCodedictList3('FMM_CHARGE_FLOW','displayValueCn'),isNull:false,length:20},
                {name:'feeFlowName',display: CSIS.Lang.ID_107020||'费用流向',width:60,type:'string'},
                {name:'isStrike',display: CSIS.Lang.ID_124640||'是否负冲销',type:'string',render:strikeRender},
                {name:'fiReceiveDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d'},
                {name:'finishDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d'},
                {name:'baseAmountWithoutTax',display: CSIS.Lang.ID_232410||'人民币不含税金额(元)',type:'hide'},
                {name:'isWarn',display: CSIS.Lang.ID_102680||'是否超期',type: 'combo',
                    valueList: [ {label: CSIS.Lang.ID_225650||'<全部>', value: '全部'},
                        {label: CSIS.Lang.ID_124660||'已超期', value: '1'},
                        {label: CSIS.Lang.ID_124670||'未超期', value: '0'}]   },
                {name:'isFreight',display: CSIS.Lang.ID_124680||'是否运费',type:'boolean'},
                {name:'sendSapDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'miscAmount',display: CSIS.Lang.ID_232420||'运杂费(元)',type:'number',isNull:true,length:12},
                {name:'sercAmount',display: CSIS.Lang.ID_232430||'服务费(元)',type:'number',isNull:true,length:12},
                {name:'otherAmount',display: CSIS.Lang.ID_232440||'其他费用(元)',type:'number',isNull:true,length:12} ,
                {name: 'unit',display: CSIS.Lang.ID_166640||'单位',type: 'comboList',editor: getCodedictList3('CDM_VOC_UNIT'),readOnly: {edit: true}},
                {name: 'unitName',display: CSIS.Lang.ID_166640||'单位'},
                {name: 'quantity', display: CSIS.Lang.ID_111650||'数量', type: 'number', length: 12, readOnly: {edit: true}},
                {name: 'price', display: CSIS.Lang.ID_107420||'单价', type: 'number', length: 12, readOnly: {edit: true}},
                {name :'sendAuditInd',display: CSIS.Lang.ID_139750||'是否送审计',type:'String',render:sendAuditIndRender},
                {name :'sendAuditUser',display: CSIS.Lang.ID_139760||'送审人员',type:'String'},
                {name :'sendAuditDate',display: CSIS.Lang.ID_139810||'送审时间',type:'String'},
                {name :'sendFiDate',display: CSIS.Lang.ID_139820||'送审财务日期（青远专用）',type:'String'},
                {name:'isEnergy',display: CSIS.Lang.ID_237370||'是否节能减排',type:'boolean'},
                {name:'isFixedAsset',display: CSIS.Lang.ID_130730||'固定资产',type:'boolean',readOnly:{edit:true}},
                {name:'ytFrom',display: '录入来源',type: 'combo',render:ytFromRender,valueList:[
                    {label:'手工录入',value:'0'},
                    {label:'远通接口',value:'1'},
                    {label:'网页接口',value:'2'},
                ]},
                {name :'excessReason',display: '理由',type:'hide',width:120},
                {name:'taxCheckState',display: '查验标记',type:'string',render:taxCheckStateRender,readOnly: {edit: false}},
                {name:'invoiceCheckCode',display: '校验码后6位',type:'String',emptyText: "-请输入校验码,普票、电子普票、卷式普票必填"},
                {name:'scScanId',display: '关联税务发票表ID',type:'hide'},
                {name: 'voyageNo',display:'航次号',type:'comboPopBox',editor:getVoyageNoPopbox()},
                {name:'portCode',width:100,display:'港口',type:'comboGrid',editor: getPortGrid(tempFields, 'portName')},
                {name:'portName',width:100,display:'港口名称',type:'String'},
                {name: 'searchVoyageNo',display:'航次号'},
                {name: 'searchPortCode',width: 100,display: '港口',type: 'comboGrid', editor: getPortGrid(tempFields, 'portName')},
                {name:'srcOrderType',display: '订单类型', readOnly:{edit: true},type: 'comboList',editor: getCodedictList2(srcOrderTypeDomain,null,srcOrderTypeExpand,srcOrderTypeSelect)} ,
                {name:'srcOrderTypeName',display: '订单类型'},
                {name:'isAdvanceFee',display: '是否预付费',type: 'combo',valueList:[
                    {label:'否',value:'0'},
                    {label:'是',value:'1'},
                ]},
                {name:'isDoubt',display: '是否疑问账单',type: 'combo',valueList:[
                    {label:'全部',value:''},{label:'确认疑问账单',value:'1'},{label:"取消疑问账单",value:'2'},{label:"解决疑问账单",value:'3'}
                ],render:isDoubtRender,width:100},
                {name:'ownOrderNo',display: 'PPM项目号',type:"string"},
                {name:'compType',display: '是否非商务费用',type: 'hide'},
                {name:'completionReportId',display: '关联id',type: 'hide'},
                {name :'passengers',display: '乘机人',type:'String'},
                {name :'voyageName',display: '航程名称',type:'String'},
                {name :'flightNumber',display: '航班号',type:'String'},
                {name :'billPrice',display: '账单价',type:'number',length:12},
                {name :'taxSubtotal',display: '税费小计',type:'number',length:12},
                {name :'serviceCharge',display: '服务费',type:'number',length:12},
                {name :'backAmount',display: '应退金额',type:'number',length:12}
            ], {search:'invoiceNo,invoiceDate.from,invoiceDate.to,payerSearch,innerOrderSearch,payee.eq,vesselCode,inputDate.from,inputDate.to,' +
            'department,groupSort,groupSortDetail,invoiceSort,invoiceSortDetail,occurTimeFrom.from,occurTimeFrom.to,feeFlow,safeFlag,finishDate.from,finishDate.to,' +
            'isWarn,currency,billNo,fiReceiveDate.from,fiReceiveDate.to,ifCanUseTax,invoiceStatus,ifJigai,amount,inputUser,orderNo,isEnergy,foreStatMonth,searchVoyageNo,searchPortCode,ytFrom',
                searchSuffix: {
                    from: CSIS.Lang.ID_227770||'从',
                    to: CSIS.Lang.ID_227780||'到'
                },
                searchConfig:{payee:{columnWidth:2/6},payerSearch:{columnWidth:2/6},orderNo:{columnWidth:2/6}},
                grid:'foreStatMonth,freightTypeName,freightName,vesselName,innerOrder,invoiceNo,currencyName,dtlAmountWithoutTax,taxRateName,dtlTaxAmount,dtlAmount,sercAmount,miscAmount,baseAmount,baseAmountWithoutTax,' +
                'amountWithoutTax,taxAmount,amount,invoiceDate,occurTimeFrom,orderNo,projectName,departmentName,customerName,' +
                'payeeName,feeFlowName,invoiceCode,invoiceDesc,currencyName,exchangeRate,ifCanUseTax,billNoName,ifJigai,safeFlag,safeItemName,remark,'+
                'sendSapDate,invoiceStatus,sendFinDate,inputUser,inputDate,contractName,isStrike,sendAuditInd,groupSortName,groupSortDetailName,voyageNo,portName,' +
                'passengers,voyageName,flightNumber,billPrice,taxSubtotal,serviceCharge,backAmount,ytFrom',
                editTab: CSIS.lang=="EN"?{
                    'invoice info':domain2EditStr,
                    'payment status':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,_space_,signer,signDate,' +
                    'isCommit,checkAmount,inputUser,inputDate,sendSapDate'
                }:{
                    '发票信息':domain2EditStr,
                    '付款状态':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,_space_,signer,signDate,' +
                    'isCommit,checkAmount,inputUser,inputDate,sendSapDate'
                },
                editConfig:{payee:{columnWidth:0.5},invoiceDesc:{columnWidth:0.75},remark:{columnWidth:0.25},excessReason:{columnWidth:0.5}},
                orderBy: 'inputDate desc ,invoiceNo ,createdDtmLoc'});

            var domain4EditStr = 'feeContractId,baseAmountWithoutTax,foreStatMonth,invoiceSort,invoiceSortDetail,billNo,vesselCode,director,department,vesselDept,payer,payee,' +
                'billQuote,checkAmount,invoiceDesc,'+
                'invoiceDate,invoiceNo,invoiceCode,orderNo,currency,exchangeRate,ifCanUseTax,feeFlow,' +
                'amountWithoutTax,taxRate,taxAmount,amount,dtlAmountWithoutTax,dtlTaxAmount,dtlAmount,baseAmount,' +
                'occurTimeFrom,occurTimeTo,isFixedAsset,safeFlag,safeItem,remark,groupSort,groupSortDetail,ifJigai,miscAmount,sercAmount,otherAmount,innerOrder,unit,quantity,portCode,isEnergy,confirmUser,signNo,excessReason,invoiceCheckCode,taxCheckState,scScanId,ownOrderNo';
            var feeInvoiceDomain4 = new C.Domain('feeInvoice', [
                {name:'feeInvoiceId'},
                {name:'feeContractId',type:'hide'},
                {name:'payeeName',display: CSIS.Lang.ID_124380||'开票单位名称',length:200,width:200},
                {name:'invoiceNo',display: CSIS.Lang.ID_112440||'发票号',length:30,width:110,type:'comboPopBox',editor:getTaxInvoiceInfoPopBox()},
                {name:'invoiceCode',display: CSIS.Lang.ID_112450||'发票代码',length:20,width:90},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',editor:currencyGrid,length:10,isNull:false},
                {name:'currencyName',display: CSIS.Lang.ID_107510||'币种',width:50},
                {name:'invoiceDate',display: CSIS.Lang.ID_112420||'发票日期',type:'date',format:'Y-m-d',maxValue:new Date()},
                {name:'groupSort',display: CSIS.Lang.ID_122290||'集团费用大类',type:'comboGrid',editor:groupSortGrid},
                {name:'groupSortName',display: CSIS.Lang.ID_122290||'集团费用大类',type:'string',width:100},
                {name:'groupSortDetail',display: CSIS.Lang.ID_122300||'集团费用类别',type:'comboGrid',editor:groupSortDetailGrid},
                {name:'groupSortDetailName',display: CSIS.Lang.ID_122300||'集团费用类别',type:'string',width:100},
                {name:'invoiceSort',display: CSIS.Lang.ID_112470||'费用类别',type:'comboGrid',editor:freightTypeGrid,isNull:false,length:5},
                {name:'freightTypeName',display: CSIS.Lang.ID_112470||'费用类别',type:'string',width:100},
                {name:'invoiceSortDetail',display: CSIS.Lang.ID_112480||'费用科目',type:'comboGrid',editor:freightGrid,isNull:false,length:10},
                {name:'freightName',display: CSIS.Lang.ID_112480||'费用科目',type:'string'},
                {name:'vesselDept',display: CSIS.Lang.ID_124390||'船舶部门',editor: getCodedictList3('PMS_VESSEL_DEPARTMENT'),type: 'comboList'},
                {name:'invoiceDesc',display: CSIS.Lang.ID_124400||'费用摘要',type:'string',length:100,width:220},
                {name:'ifCanUseTax',display: CSIS.Lang.ID_112540||'是否增值税',type: 'combo',valueList:[
                    {label:CSIS.Lang.ID_237310||'普通发票',value:'0'},
                    {label:CSIS.Lang.ID_237320||'增值税专用发票',value:'1'},
                    {label:CSIS.Lang.ID_237330||'增值税普通发票',value:'2'},
                    {label:CSIS.Lang.ID_237331||'增值税普通发票(电子)',value:'3'},
                    {label:CSIS.Lang.ID_237332||'增值税普通发票(卷式)',value:'4'},
                    {label:'增值税专用电子发票',value:'5'},
                    {label:'电子发票(增值税专用发票)',value:'6'},
                    {label:'电子发票(增值税普通发票)',value:'7'}
                ]} ,
                {name:'taxFlag',display: CSIS.Lang.ID_124420||'费用含税标志',length:10},
                {name:'taxRate',display: CSIS.Lang.ID_107600||'税率',type:'comboList',editor:getCodedictList3('FMM_RATE_TAX_OTHER',null,null,taxRateOnSelected),length:12},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率',type:'string'},
                {name:'amountWithoutTax',display: CSIS.Lang.ID_237350||'不含税总金额(元)',type:'number',length:12},
                {name:'taxAmount',display: CSIS.Lang.ID_232330||'发票总税额(元)',type:'number',length:12},
                {name:'vesselCode',display: CSIS.Lang.ID_100050||'船舶',type:'comboGrid',editor:getVesselGrid(null,tempFields,null,vesselGridOnSelected),length:10,isNull:false},
                {name:'vesselName',display: CSIS.Lang.ID_100050||'船舶',type:'string',width:100},
                {name:'exchangeRate',display: CSIS.Lang.ID_107520||'汇率',length:18,width:70,isNull:false},
                {name:'baseAmount',display: CSIS.Lang.ID_112580||'人民币金额(元)',type:'number',length:12},
                {name:'gatheringLinkman',display: CSIS.Lang.ID_124430||'收款联系人',readOnly:{edit:true},length:50},
                {name:'futurePrice',display: CSIS.Lang.ID_124440||'预估金额',readOnly:{edit:true},type:'number',length:12},
                {name:'billQuote',display: CSIS.Lang.ID_124450||'账单报价',type:'number',length:12},
                {name:'occurTimeFrom',display: CSIS.Lang.ID_123940||'完工日期',type:'date',format:'Y-m-d',maxValue:new Date()},
                {name:'occurTimeTo',display: CSIS.Lang.ID_124460||'发生时间到',type:'hide',format:'Y-m-d'},
                {name:'payee',display: CSIS.Lang.ID_112500||'开票单位',type:'comboPopBox',editor:getCustomerPopBox('GYS',tempFields,'payeeName',null,payeeOnSelected),isNull:false},
                {name:'payer',display: CSIS.Lang.ID_107240||'付款单位',width:170,type:'comboPopBox',editor:getOfficePopBox(tempFields,'customerName',null,payerSelected),isNull:false},
                {name:'payerSearch',display: CSIS.Lang.ID_107240||'付款单位',type:'comboPopBox',editor:getOfficePopBoxChecked(beforeOfficeExtend)},
                {name:'customerName',display: CSIS.Lang.ID_107240||'付款单位',type:"string",width:170},
                {name:'signNo',display: CSIS.Lang.ID_107780||'签收单号',readOnly:{edit:true}},
                {name:'signer',display: CSIS.Lang.ID_107790||'签收人',readOnly:{edit:true}},
                {name:'signDate',display: CSIS.Lang.ID_115710||'签收日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'isSendFin',display: CSIS.Lang.ID_112640||'是否已送财务',type:'boolean'},
                {name:'sendFinDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'sendSapDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'confirmUser',display: CSIS.Lang.ID_124480||'经办人',readOnly:{edit:true}},
                {name:'projectName',display: CSIS.Lang.ID_124490||'是否挂单',readOnly:{edit:true}},
                {name:'billNo',display: CSIS.Lang.ID_237400||'结算编号',readOnly: {edit: true}},
                {name:'confirmDate',display: CSIS.Lang.ID_124510||'制单日期',type:'date',format:'Y-m-d',readOnly:{edit:true}},
                {name:'invoiceStatus',display: CSIS.Lang.ID_112610||'发票状态',readOnly:{edit:true},type:'comboList',editor:{
                    type:'list',
                    domain: currencyDomain,
                    searchChecked:true ,
                    allText:CSIS.Lang.ID_107180||'全选',
                    addAllSelector: true,
                    valueField:"value",
                    displayField:"label",
                    store:CSIS.Ext.createValueListStore([
                        {label: CSIS.Lang.ID_115590||'新增', value: '1'},
                        {label: CSIS.Lang.ID_119620||'未审核', value: '3'},
                        {label: CSIS.Lang.ID_110270||'已审核', value: '4'},
                        {label: CSIS.Lang.ID_115630||'已付款', value: '5'},
                        {label: '退票', value: '6'}])
                },render:stateRender,width:70},
                {name:'sendStatus',display: CSIS.Lang.ID_107540||'发送状态',readOnly:{edit:true},length:1},
                {name:'ifSendFi',display: CSIS.Lang.ID_124520||'是否发送财务',type:'boolean'},
                {name:'paymentNoticeId',display: CSIS.Lang.ID_230090||'付款单ID'},
                {name:'ifAudit',display: CSIS.Lang.ID_119740||'是否审核',type:'boolean',readOnly:{edit:true}},
                {name:'amount',display: CSIS.Lang.ID_112530||'发票总金额(元)',type:'number',length:12},
                {name:'dtlAmount',display: CSIS.Lang.ID_232190||'含税金额(元)',type:'number',readOnly:true,length:12},
                {name:'dtlTaxAmount',display: CSIS.Lang.ID_107610||'税额(元)',type:'number',length:12},
                {name:'dtlAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额(元)',type:'number',length:12},
                {name:'innerOrderSearch',display: CSIS.Lang.ID_110210||'订单号',type:'string'},
                {name:'innerOrder',display: CSIS.Lang.ID_110210||'订单号',type:'comboPopBox',editor:getPartsOrderPopBox(),width:200,render: innerOrderRender},
                {name:'orderNo',display: CSIS.Lang.ID_124540||'付款单号',readOnly:{edit:true},width:100,render: orderNoRender},
                {name:'contractNo',display: CSIS.Lang.ID_124550||'合同',type:'comboGrid',editor:feeContractGrid},
                {name:'contractName',display: CSIS.Lang.ID_124550||'合同'},
                {name:'isCommit',display: CSIS.Lang.ID_124560||'是否提交',type:'boolean',readOnly:{edit:true}},
                {name:'checkAmount',display: CSIS.Lang.ID_139380||'核定金额(元)',type:'number',length:12},
                {name:'inputUser',display: CSIS.Lang.ID_112670||'录入人',readOnly:{edit:true},width:70},
                {name:'inputDate',display: CSIS.Lang.ID_112660||'录入日期',type:'date',format:'Y-m-d',readOnly:{edit:true},width:100},
                {name:'foreStatMonth',display: CSIS.Lang.ID_124570||'入账年度',type:'date',format:'Y',isNull:false,width:55},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string',length:200,width:200},
                {name:'ifJigai',display: CSIS.Lang.ID_124580||'库存管理',type:'boolean'},
                {name:'isFixedAsset',display: CSIS.Lang.ID_130730||'固定资产',type:'boolean'},
                {name:'safeFlag',display: CSIS.Lang.ID_124590||'是否属安全费',type:'boolean'},
                {name:'safeItem',display: CSIS.Lang.ID_124591||'安全费类别',type:'comboList',editor:getCodedictList3('FMM_SAFE_ITEM','displayValueCn',null,safeItemOnSelected,true),length:20},
                {name:'safeItemName',display: CSIS.Lang.ID_124591||'安全费类别',width:90,type:'string'},
                {name:'director',display: CSIS.Lang.ID_124600||'主管',width:60,type:'comboList',editor:directorList,render:renderDirector},
                {name:'usrName',display: CSIS.Lang.ID_124600||'主管',width:60,type:'string'},
                {name:'departmentName',display: CSIS.Lang.ID_124610||'船管部门',width:110,type:'string',length:100},
                {name:'department', display: CSIS.Lang.ID_124610||'船管部门', type:'comboTree', editor:fix_officeTree},
                {name:'feeFlow',display: CSIS.Lang.ID_107020||'费用流向',type:'comboList',editor:getCodedictList3('FMM_CHARGE_FLOW','displayValueCn'),isNull:false,length:20},
                {name:'feeFlowName',display: CSIS.Lang.ID_107020||'费用流向',width:60,type:'string'},
                {name:'isStrike',display: CSIS.Lang.ID_124640||'是否负冲销',type:'string',render:strikeRender},
                {name:'fiReceiveDate',display: CSIS.Lang.ID_124470||'付款日期',type:'date',format:'Y-m-d'},
                {name:'finishDate',display: CSIS.Lang.ID_232400||'送SAP时间',type:'date',format:'Y-m-d'},
                {name:'baseAmountWithoutTax',display: CSIS.Lang.ID_232410||'人民币不含税金额(元)',type:'hide'},
                {name:'isWarn',display: CSIS.Lang.ID_102680||'是否超期',type: 'combo',
                    valueList: [ {label: CSIS.Lang.ID_225650||'<全部>', value: '全部'},
                        {label: CSIS.Lang.ID_124660||'已超期', value: '1'},
                        {label: CSIS.Lang.ID_124670||'未超期', value: '0'}]   },
                {name:'miscAmount',display: CSIS.Lang.ID_232420||'运杂费(元)',type:'number',isNull:true,length:12},
                {name:'sercAmount',display: CSIS.Lang.ID_232430||'服务费(元)',type:'number',isNull:true,length:12},
                {name:'otherAmount',display: CSIS.Lang.ID_232440||'其他费用(元)',type:'number',isNull:true,length:12},
                {name: 'unit',display: CSIS.Lang.ID_166640||'单位',type: 'comboList',editor: getCodedictList3('CDM_VOC_UNIT'),readOnly: {edit: true}},
                {name: 'unitName',display: CSIS.Lang.ID_166640||'单位'},
                {name: 'quantity', display: CSIS.Lang.ID_111650||'数量', type: 'number', length: 12, readOnly: {edit: true}},
                {name: 'price', display: CSIS.Lang.ID_107420||'单价', type: 'number', length: 12, readOnly: {edit: true}},
                {name: 'portCode', display: CSIS.Lang.ID_139650||'签收港口', type: 'string', length: 20, readOnly: {edit: true}},
                {name:'equipUse',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,type:'hide'},
                {name:'equipUse1',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_EUQIP_KIND'),type:'hide'},
                {name:'equipUse2',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_LPA_KIND'),type:'hide'},
                {name:'equipUse3',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_MTR_KIND'),type:'hide'},
                {name:'equipUse4',display: CSIS.Lang.ID_139660||'签收港口',isNull:true,editor:getCodedictList3('DY_PAINT_KIND'),type:'hide'},
                {name:'equip',display: CSIS.Lang.ID_139670||'设备数量',isNull:true,length:12},
                {name:'payeeOrder',display: CSIS.Lang.ID_139680||'供应商订单号',isNull:true},
                {name:'ownOrderNo',display: 'PPM项目号',type:"string"},
                {name:'purchaseDate',display: CSIS.Lang.ID_139700||'采购日期',isNull:true,type:'date',format:'Y-m-d'},
                {name:'equipBillQuote',display: CSIS.Lang.ID_139710||'订单金额',isNull:true,length:12},
                {name:'equipBillCurrency',display: CSIS.Lang.ID_139720||'订单币种',isNull:true,editor:equipCurrencyGrid},
                {name:'equipBillCurrencyName',display: CSIS.Lang.ID_139720||'订单币种'},
                {name:'equipBillRate',display: CSIS.Lang.ID_107520||'汇率',isNull:true,length:18},
                {name:'equipBillRmb',display: CSIS.Lang.ID_139730||'折合人民币金额',isNull:true,length:12},
                {name:'invoiceSortDy',display: CSIS.Lang.ID_112470||'费用类别'},
                {name:'invoiceSortDetailDy',display: CSIS.Lang.ID_112480||'费用科目'},
                {name: 'dyTaxRate', display: CSIS.Lang.ID_107600||'税率',type:'comboList',editor:getCodedictList3('FMM_TAX_RATE',null,null,taxRateDyOnSelected),length:14},
                {name: 'dyAmount', display: CSIS.Lang.ID_139740|| '税后金额',type:'number',length:14},
                {name :'sendAuditInd',display: CSIS.Lang.ID_139750||'是否送审计',type:'String',render:sendAuditIndRender},
                {name :'sendAuditUser',display: CSIS.Lang.ID_139760||'送审人员',type:'String'},
                {name :'sendAuditDate',display: CSIS.Lang.ID_139810||'送审时间',type:'date',format:'Y-m-d'},
                {name :'sendFiDate',display: CSIS.Lang.ID_139780||'送财务时间',type:'date',format:'Y-m-d'},
                {name:'isEnergy',display: CSIS.Lang.ID_237370||'是否节能减排',type:'boolean'},
                {name:'isTickets',display: CSIS.Lang.ID_237390||'是否已开票',type: 'combo',
                    valueList: [ {label: CSIS.Lang.ID_225650||CSIS.Lang.ID_225650||'<全部>', value: '全部'},
                        {label: CSIS.Lang.ID_237410||'已开票', value: '1'},
                        {label: CSIS.Lang.ID_221660||'未开票', value: '0'}]},
                {name :'excessReason',display: '理由',type:'hide',width:120},
                {name:'taxCheckState',display: '税务系统查验通过标记',type:'hide'},
                {name:'invoiceCheckCode',display: '校验码后6位',type:'string',emptyText: "-请输入校验码,普票、电子普票、卷式普票必填"},
                {name:'scScanId',display: '关联税务发票表ID',type:'hide'},
                {name:'isDoubt',display: '是否疑问账单',type: 'combo',valueList:[
                    {label:'全部',value:''},{label:'确认疑问账单',value:'1'},{label:"取消疑问账单",value:'2'},{label:"解决疑问账单",value:'3'}
                ],render:isDoubtRender,width:100},
                {name:'compType',display: '是否非商务费用',type: 'hide'}
            ], {search:'invoiceNo,invoiceDate.from,invoiceDate.to,payerSearch,innerOrderSearch,payee.eq,vesselCode,inputDate.from,inputDate.to,' +
            'department,groupSort,groupSortDetail,invoiceSort,invoiceSortDetail,occurTimeFrom.from,occurTimeFrom.to,feeFlow,safeFlag,finishDate.from,finishDate.to,' +
            'isWarn,currency,billNo,fiReceiveDate.from,fiReceiveDate.to,ifCanUseTax,invoiceStatus,ifJigai,isFixedAsset,amount,inputUser,isTickets,orderNo,isEnergy',
                searchSuffix: {
                    from: CSIS.Lang.ID_227770||'从',
                    to: CSIS.Lang.ID_227780||'到'
                },
                searchConfig:{payee:{columnWidth:CSIS.lang=="EN"?1/4:2/6},payerSearch:{columnWidth:CSIS.lang=="EN"?1/4:2/6},orderNo:{columnWidth:CSIS.lang=="EN"?1/4:2/6}},
                grid:'foreStatMonth,freightTypeName,freightName,vesselName,innerOrder,invoiceNo,currencyName,dtlAmountWithoutTax,taxRateName,dtlTaxAmount,dtlAmount,sercAmount,miscAmount,baseAmount,baseAmountWithoutTax,' +
                'amountWithoutTax,taxAmount,amount,invoiceDate,occurTimeFrom,orderNo,projectName,director,departmentName,customerName,' +
                'payeeName,feeFlowName,invoiceCode,invoiceDesc,currencyName,exchangeRate,ifCanUseTax,billNo,ifJigai,isFixedAsset,safeFlag,safeItemName,remark,'+
                'invoiceStatus,sendFinDate,inputUser,inputDate,confirmDate,sendSapDate,contractName,isStrike,sendAuditInd,sendAuditDate,sendFiDate,groupSortName,groupSortDetailName',
                editTab: CSIS.lang=="EN"?{
                    'invoice info':domain4EditStr,
                    'payment status':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,signer,signDate,' +
                    'isCommit,inputUser,inputDate,sendSapDate',
                    'order item':'invoiceSortDy,invoiceSortDetailDy,equipUse,equipUse1,equipUse2,equipUse3,equipUse4,equip,payeeOrder,purchaseDate,equipBillQuote,'+
                    'equipBillCurrency,equipBillRate,equipBillRmb,dyTaxRate,dyAmount'
                }:{
                    '发票信息':domain4EditStr,
                    '付款状态':'gatheringLinkman,futurePrice,sendFinDate,confirmDate,invoiceStatus,sendStatus,ifAudit,signer,signDate,' +
                    'isCommit,inputUser,inputDate,sendSapDate'
                },
                editConfig:{payee:{columnWidth:0.5},payer:{columnWidth:0.5},invoiceDesc:{columnWidth:0.5},remark:{columnWidth:0.5},invoiceNo:{readOnly:true},excessReason:{columnWidth:0.5}},
                orderBy: 'inputDate desc ,invoiceNo ,createdDtmLoc'});

            var btnMainAdd = Ext.create('Ext.button.Button',{
                text:CSIS.Lang.ID_100230||'增加',icon:'../res/img/themes/default/edit.png',
                handler: function() {
                    btnStatus="create";
                    tabs.setActiveTab(1);
                    Ext.getElementById(page.getToolbarBox().getButton('create').getId()).click();
                }
            });

            var btnMainEdit = Ext.create('Ext.button.Button',{
                text:CSIS.Lang.ID_100250||'编辑',icon:'../res/img/themes/default/edit.png',
                handler: function() {
                    var selectRecord = page.getGridBox().getSelectedRecord();
                    if(selectRecord==null){
                        Ext.MessageBox.alert("系统提示","请选择一条记录！");
                        return;
                    }
                    btnStatus="edit";
                    tabs.setActiveTab(1);
                    Ext.getElementById(page.getToolbarBox().getButton('edit').getId()).click();
                }
            });

            var btnMainRemove = Ext.create('Ext.button.Button',{
                text:CSIS.Lang.ID_100280||'删除',icon:'../res/img/themes/default/edit.png',
                handler: function() {
                    var selectRecord = page.getGridBox().getSelectedRecord();
                    if(selectRecord==null){
                        Ext.MessageBox.alert("系统提示","请选择一条记录！");
                        return;
                    }
                    tabs.setActiveTab(1);
                    Ext.getElementById(page.getToolbarBox().getButton('remove').getId()).click();
                }
            });

            var btnNegReversal = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_124900||'负冲销',icon:'../res/img/themes/default/arrow_left.png',
                        handler:function(){
                            var checkRecords = page.getGridBox().getCheckedRecords();
                            if(checkRecords==null||checkRecords.length==0){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_113790||"请选择一条记录！");
                            }else if(checkRecords.length>1){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","只能选中一条发票记录进行负冲销！");
                            }else{
                                Ext.MessageBox.confirm(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_124850||'确定负冲销？',function(btn){
                                    if(btn == 'yes'){
                                        C.ajax.callAction('negative','feeInvoice',checkRecords[0],function(action,domainName,resp){
                                            if(resp && resp.success){
                                                var select = page.getGrid().getSelectionModel().getSelection()
                                                Ext.each(select,function(v){
                                                    v.set('isStrike','1');
                                                    v.commit();
                                                });
                                                btnNegReversal.setDisabled(true);
                                            }
                                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",resp.msg);
                                        });
                                    }
                                })
                            }
                        }
                    })

            var btnNegReversal_sub = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_124900||'负冲销',icon:'../res/img/themes/default/arrow_left.png',handler:function(){
                            Ext.getElementById(btnNegReversal.getId()).click()  } });
            var fieldMap = new C.HashMap();
            fieldMap.put('invoiceNo','INVOICE_NO'); fieldMap.put('invoiceDate.from','INVOICE_DATE');
            fieldMap.put('invoiceDate.to','INVOICE_DATE'); fieldMap.put('payee','PAYEE');
            fieldMap.put('vesselCode','VESSEL_CODE'); fieldMap.put('inputDate.from','INPUT_DATE');
            fieldMap.put('inputDate.to','INPUT_DATE'); fieldMap.put('department','DEPARTMENT');
            fieldMap.put('invoiceSort','INVOICE_SORT');   fieldMap.put('invoiceSortDetail','INVOICE_SORT_DETAIL');
            fieldMap.put('occurTimeFrom.from','OCCUR_TIME_FROM');   fieldMap.put('occurTimeFrom.to','OCCUR_TIME_FROM');
            fieldMap.put('orderNo','ORDER_NO'); fieldMap.put('safeFlag','SAFE_FLAG');
            fieldMap.put('currency','CURRENCY');  fieldMap.put('billNo','BILL_NO');
            fieldMap.put('ifCanUseTax','IF_CAN_USE_TAX'); fieldMap.put('invoiceStatus','INVOICE_STATUS');
            fieldMap.put('ifJigai','IF_JIGAI');fieldMap.put('amount','AMOUNT');
            fieldMap.put('inputUser','INPUT_USER');
            var btnExport= Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_112710||'导出签收单',icon:'../res/img/themes/default/application_go.png',
                        handler:function(){
                            var val  = page.getSearchBox().getValues(true);
                            var allRecord = page.getGridBox().getGridAllRecords();
                            var checkRecords = page.getGridBox().getCheckedRecords();
                            var param="";
                            if((checkRecords.length == 0||allRecord.length==0)&&isEmpty(val['vesselCode'])) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139830||"请先根据船舶查询数据！");
                                return;
                            }else if(checkRecords.length>0){
                                var ids = '';
                                var vesselFlag = true;
                                for(var i=0; i<checkRecords.length; i++){
                                    if(checkRecords[i].vesselName!=checkRecords[0].vesselName){
                                        vesselFlag = false;
                                        break;
                                    }
                                    ids += "'"+checkRecords[i].feeInvoiceId +  "',";
                                }
                                if(!vesselFlag){
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139840||"请选择相同船舶的数据再导出！");
                                    return;
                                }
                                ids = ids.substring(0,ids.length-1);
                                param+=" AND FI.FEE_INVOICE_ID in ("+ids+")"
                            }else{
                                for(var p in val){
                                    if(!isEmpty(val[p])){
                                        if(p=='invoiceDate.from'||p=='inputDate.from'||p=='occurTimeFrom.from'){
                                            param+=" AND FI."+fieldMap.get(p)+" >=to_date('"+val[p]+"','yyyy-MM-dd')";
                                        }else if(p=='invoiceDate.to'||p=='inputDate.to'||p=='occurTimeFrom.to'){
                                            param+=" AND FI."+fieldMap.get(p)+" <=to_date('"+val[p]+"','yyyy-MM-dd HH24:mi:ss')";
                                        }else if(p=="payerSearch"){
                                            var array = val.payerSearch.split('、');
                                            param +=" AND PAYER IN (";
                                            for (var i in array) {
                                                param += "'" + array[i] + "',"
                                            }
                                            param = param.substring(0, param.length - 1) + ")";
                                        }else if(p=="finishDate.from"||p=="finishDate.to"){
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["finishDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  "  AND FI.SEND_SAP_DATE <= TO_DATE('" + val["finishDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                        }else if(p=="isWarn"){
                                            if(val['isWarn'] == "1"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE > 90)";
                                            }else if(val['isWarn'] == "0"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE <= 90)";
                                            }
                                        }else if(p=="fiReceiveDate.from"||p=="fiReceiveDate.to"){
                                            param += "AND EXISTS(SELECT 1 FROM FMM_FEE_PAYMENT_NOTICE P " +
                                                    "WHERE FI.PAYMENT_NOTICE_ID=P.PAYMENT_NOTICE_ID";
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["fiReceiveDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  " AND FI.SEND_SAP_DATE <= TO_DATE('" + val["fiReceiveDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                            param += ")"

                                        } else{
                                            param+=" AND FI."+fieldMap.get(p)+" = '"+val[p]+"'";
                                        }
                                    }
                                }
                            }
                            open(C.reportServerPath + "=report%2FSP_FMM_FEE_INVOICE_EXPORT.cpt&format=excel" +
                                    "&I_SQL_PARAM="+param +
                                    "&I_TYPE=1"+
                                    "&I_USER_NAME="+userName);
                        }
                    });

            var btnSendAuditBill= Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_139860||'送审计账单',icon:'../res/img/themes/default/application_go.png',
                        handler:function(){
                            var val  = page.getSearchBox().getValues(true);
                            var allRecord = page.getGridBox().getGridAllRecords();
                            var checkRecords = page.getGridBox().getCheckedRecords();
                            var selectRecord = page.getGridBox().getSelectedRecord();
                            var param="";
                            if((checkRecords.length == 0||allRecord.length==0)&&isEmpty(val['vesselCode'])) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139830||"请先根据船舶查询数据！");
                                return;
                            }
                            var feeInvoiceIdStr = "";
                            if(checkRecords.length>0){
                                var ids = '';
                                var vesselFlag = true;
                                for(var i=0; i<checkRecords.length; i++){
                                    ids += "'"+checkRecords[i].feeInvoiceId +  "',";
                                    feeInvoiceIdStr+=checkRecords[i].feeInvoiceId+",";
                                }
                                ids = ids.substring(0,ids.length-1);
                                feeInvoiceIdStr= feeInvoiceIdStr.substring(0,feeInvoiceIdStr.length-1);
                                param+=" AND FI.FEE_INVOICE_ID in ("+ids+")"
                            }else{
                                for(var p in val){
                                    if(!isEmpty(val[p])){
                                        if(p=='invoiceDate.from'||p=='inputDate.from'||p=='occurTimeFrom.from'){
                                            param+=" AND FI."+fieldMap.get(p)+" >=to_date('"+val[p]+"','yyyy-MM-dd')";
                                        }else if(p=='invoiceDate.to'||p=='inputDate.to'||p=='occurTimeFrom.to'){
                                            param+=" AND FI."+fieldMap.get(p)+" <=to_date('"+val[p]+"','yyyy-MM-dd HH24:mi:ss')";
                                        }else if(p=="payerSearch"){
                                            var array = val.payerSearch.split('、');
                                            param +=" AND PAYER IN (";
                                            for (var i in array) {
                                                param += "'" + array[i] + "',"
                                            }
                                            param = param.substring(0, param.length - 1) + ")";
                                        }else if(p=="finishDate.from"||p=="finishDate.to"){
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["finishDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  "  AND FI.SEND_SAP_DATE <= TO_DATE('" + val["finishDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                        }else if(p=="isWarn"){
                                            if(val['isWarn'] == "1"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE > 90)";
                                            }else if(val['isWarn'] == "0"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE <= 90)";
                                            }
                                        }else if(p=="fiReceiveDate.from"||p=="fiReceiveDate.to"){
                                            param += "AND EXISTS(SELECT 1 FROM FMM_FEE_PAYMENT_NOTICE P " +
                                                    "WHERE FI.PAYMENT_NOTICE_ID=P.PAYMENT_NOTICE_ID";
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["fiReceiveDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  " AND FI.SEND_SAP_DATE <= TO_DATE('" + val["fiReceiveDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                            param += ")"

                                        } else{
                                            param+=" AND FI."+fieldMap.get(p)+" = '"+val[p]+"'";
                                        }
                                    }
                                }
                            }
                            searchParams._extend = param;
                            searchParams.sendFlag = "1";
                            searchParams.userName = userName;
                            var storageProgress = new  CSIS.UploadWindow();
                            storageProgress.startDownload("feeInvoice",CSIS.Lang.ID_237430||"送审计账单.xls",searchParams);

                            if(feeInvoiceIdStr.length>0){
                                C.ajax.callAction('sendAuditBill','feeInvoice',{user:userName,date:new Date(),feeInvoiceId:ids},function(action,domainName,resp){
                                    if(resp && resp.success){
                                        Ext.getElementById(page.getSearchBox().getSearchButton().getId()).click();
                                    }
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",resp.msg);
                                });
                            }
                        }
                    });


            var btnSendFincBill= Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_139870||'财务账单',icon:'../res/img/themes/default/application_go.png',
                        handler:function(){
                            var val  = page.getSearchBox().getValues(true);
                            var allRecord = page.getGridBox().getGridAllRecords();
                            var checkRecords = page.getGridBox().getCheckedRecords();
                            var selectRecord = page.getGridBox().getSelectedRecord();
                            var param="";
                            if((checkRecords.length == 0||allRecord.length==0)&&isEmpty(val['vesselCode'])) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139830||"请先根据船舶查询数据！");
                                return;
                            }

                            var feeInvoiceIdStr = "";
                            if(checkRecords.length>0){
                                var ids = '';
                                var vesselFlag = true;
                                for(var i=0; i<checkRecords.length; i++){
                                    ids += "'"+checkRecords[i].feeInvoiceId +  "',";
                                    feeInvoiceIdStr+=checkRecords[i].feeInvoiceId+",";
                                }
                                ids = ids.substring(0,ids.length-1);
                                feeInvoiceIdStr= feeInvoiceIdStr.substring(0,feeInvoiceIdStr.length-1);
                                param+=" AND FI.FEE_INVOICE_ID in ("+ids+")"
                            }else{
                                for(var p in val){
                                    if(!isEmpty(val[p])){
                                        if(p=='invoiceDate.from'||p=='inputDate.from'||p=='occurTimeFrom.from'){
                                            param+=" AND FI."+fieldMap.get(p)+" >=to_date('"+val[p]+"','yyyy-MM-dd')";
                                        }else if(p=='invoiceDate.to'||p=='inputDate.to'||p=='occurTimeFrom.to'){
                                            param+=" AND FI."+fieldMap.get(p)+" <=to_date('"+val[p]+"','yyyy-MM-dd HH24:mi:ss')";
                                        }else if(p=="payerSearch"){
                                            var array = val.payerSearch.split('、');
                                            param +=" AND PAYER IN (";
                                            for (var i in array) {
                                                param += "'" + array[i] + "',"
                                            }
                                            param = param.substring(0, param.length - 1) + ")";
                                        }else if(p=="finishDate.from"||p=="finishDate.to"){
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["finishDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  "  AND FI.SEND_SAP_DATE <= TO_DATE('" + val["finishDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                        }else if(p=="isWarn"){
                                            if(val['isWarn'] == "1"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE > 90)";
                                            }else if(val['isWarn'] == "0"){
                                                param += " AND (FI.INPUT_DATE - FI.INVOICE_DATE <= 90)";
                                            }
                                        }else if(p=="fiReceiveDate.from"||p=="fiReceiveDate.to"){
                                            param += "AND EXISTS(SELECT 1 FROM FMM_FEE_PAYMENT_NOTICE P " +
                                                    "WHERE FI.PAYMENT_NOTICE_ID=P.PAYMENT_NOTICE_ID";
                                            if( p=="finishDate.from") {
                                                param +=" AND FI.SEND_SAP_DATE >= TO_DATE('" + val["fiReceiveDate.from"] +"','yyyy-MM-dd')"
                                            }
                                            if( val["finishDate.to"] != '')  {
                                                param +=  " AND FI.SEND_SAP_DATE <= TO_DATE('" + val["fiReceiveDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                                            }
                                            param += ")"

                                        } else{
                                            param+=" AND FI."+fieldMap.get(p)+" = '"+val[p]+"'";
                                        }
                                    }
                                }
                            }
                            searchParams._extend = param;
                            searchParams.sendFlag = "0";
                            searchParams.userName = userName;
                            var storageProgress = new  CSIS.UploadWindow();
                            storageProgress.startDownload("feeInvoice",CSIS.Lang.ID_237440||"送财务账单.xls",searchParams);

                            if(feeInvoiceIdStr.length>0){
                                C.ajax.callAction('sendFincBill','feeInvoice',{date:new Date(),feeInvoiceId:ids},function(action,domainName,resp){
                                    if(resp && resp.success){
                                        Ext.getElementById(page.getSearchBox().getSearchButton().getId()).click();
                                    }
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139880||"送财务成功");
                                });
                            }
                        }
                    });

            var rebackUpdateBtn = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_261280||'撤回修改',icon:'../res/img/themes/default/application_go.png',
                        handler:function(){
                            var selectRecord = page.getGridBox().getSelectedRecord();
                            var result = rebackUpdateBtnValidate(selectRecord)
                            if(!isEmpty(result)){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",result);
                                return;
                            }
                            page.getToolbarBox().getButton('edit').setDisabled(false);
                            document.getElementById(page.getToolbarBox().getButton('edit').id).click();
                            rollbackUpdateFlag = true;
                            rebackUpdateBtn.disable();
                        }
                    });
            var scanBtn = Ext.create("Ext.button.Button", {text:CSIS.Lang.ID_251890||"扫描",icon:'../res/img/themes/default/application_put.png',
                handler: function () {
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();

                    if (companyCode&&companyCode.startWith("65")) {
                        C.ajax.callAction('getVesselManByType2VesCode','vesselManagement',{vesselCode:vesselCode,managementType:'6'},function(action,domainName,resp){
                            if(!isEmpty(resp.msg) && (resp.msg.startWith("65") || resp.msg.startWith("6300"))){
                                page.getEditBox().setReadOnly('invoiceNo', true);
                                page.getEditBox().setReadOnly('invoiceCode', true);
                                page.getEditBox().setReadOnly('invoiceDate', true);
                                var selectRecord = page.getGridBox().getSelectedRecord();
                                idScanBtnChange = scanWindow(feeInvoiceDomain,selectRecord,page);
                            }else{
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","请先选择船舶！");
                            }

                        });
                    } else {
                        C.ajax.callAction('getVesselManagemenet','vesselManagement',{vesselCode:vesselCode},function(action,domainName,resp){
                            if(!isEmpty(resp.msg) && (resp.msg.startWith("65")||resp.msg.startWith("68")||resp.msg.startWith("66")||resp.msg.startWith("0802"))){
                                page.getEditBox().setReadOnly('invoiceNo', true);
                                page.getEditBox().setReadOnly('invoiceCode', true);
                                page.getEditBox().setReadOnly('invoiceDate', true);
                                var selectRecord = page.getGridBox().getSelectedRecord();
                                idScanBtnChange = scanWindow(feeInvoiceDomain,selectRecord,page);
                            }else{
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","请先选择船舶！");
                            }

                        });
                    }

                }
            });

            var doubtOrRevokeBtnId = Ext.id();
            var doubtOrRevokeBtn = Ext.create('Ext.button.Button', {id:doubtOrRevokeBtnId,
                text: CSIS.Lang.ID_251900||'疑问账单', icon: '../res/img/themes/default/application_go.png',
                handler: function () {
                    var checkRecords = page.getGridBox().getCheckedRecords();
                    var msg = doubtOrRevokeBtnValidate(checkRecords,"FMM")
                    if(!isEmpty(msg)){
                        Ext.MessageBox.alert("信息",msg);
                        return;
                    }
                    var refreshParam = doubtOrRevokeShowWindowBox('疑问账单',"fmm/doubtFeeInvoiceWindow.jsp",checkRecords,page.getGridBox(),"FMM",enquireType);
                }
            })

            var doubtOrRevokeBtn_sub = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_251900||'疑问账单',icon:'../res/img/themes/default/application_go.png',handler:function(){
                        Ext.getElementById(doubtOrRevokeBtn.getId()).click()  } });

            var rejectInvoiceBtnId = Ext.id();
            var rejectInvoiceBtn = Ext.create('Ext.button.Button', {id:rejectInvoiceBtnId,
                text: CSIS.Lang.ID_251900||'退票/取消', icon: '../res/img/themes/default/application_go.png',
                handler: function () {
                    var checkRecords = page.getGridBox().getCheckedRecords();
                    var msg = rejectInvoiceBtnValidate(checkRecords)
                    if(!isEmpty(msg)){
                        Ext.MessageBox.alert("信息",msg);
                        return;
                    }
                    var recordInvoiceStatus = checkRecords[0].invoiceStatus;
                    var tip = recordInvoiceStatus=="6"?"是否确定取消退票？":"是否确定退票？"
                    var status = recordInvoiceStatus=="6"?"7":"6";

                    Ext.MessageBox.confirm(CSIS.Lang.ID_162160||'系统提示', tip, function (btn) {
                        if (btn == "yes") {
                            msg = rejectInvoiceBtnUpdate(checkRecords,status)
                            if(!isEmpty(msg)){
                                var stores = page.getGrid().getSelectionModel().getSelection();
                                Ext.each(stores,function(v){
                                    v.set('invoiceStatus',status);
                                    v.commit();
                                });
                                Ext.MessageBox.alert("信息",msg);
                                return;
                            }
                        }
                    })
                }
            })

            var rejectInvoiceBtn_sub = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_251910||'退票',icon:'../res/img/themes/default/application_go.png',handler:function(){
                        Ext.getElementById(rejectInvoiceBtn.getId()).click()  } });
            var dataModBtn = Ext.create('Ext.button.Button',{text:'数据变更',icon:'../res/img/themes/default/application_go.png',handler:function(){
                    var selectRecord = page.getGridBox().getSelectedRecord()
                    if(selectRecord==null){
                        Ext.MessageBox.alert("提示","请选择一条记录");
                        return;
                    }
                    selectRecord.moduleCode = "FMM";
                    selectRecord.moduleName = "费用管理";
                    dataModFn(selectRecord,selectRecord.feeInvoiceId);
                }
            });
            var btnPaymentNotice_sub = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_136640||'生成付款单',icon:'../res/img/themes/default/note_go.png',
                handler:function(){
                    Ext.getElementById(btnPaymentNotice.getId()).click()
                }
            });

            var btnViewInnerOrder = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_251970||'查看订单',icon:'../res/img/themes/default/search.png',
                handler:function(){
                    var selectRecord = page.getGridBox().getSelectedRecord()
                    if(selectRecord==null){
                        Ext.MessageBox.alert("提示","请选择一条记录");
                        return;
                    }
                    var invoiceSort = selectRecord.invoiceSort
                    var invoiceSortDetail = selectRecord.invoiceSortDetail
                    var innerOrder = selectRecord.innerOrder
                    if(invoiceSort == "FY70"){
                        var url = ''
                        if(invoiceSortDetail=='FY70001') url = 'vdm/chartsOrderConfirm.jsp?innerOrder='+innerOrder
                        else if(invoiceSortDetail=='FY70002') url = 'vdm/papersOrderConfirm.jsp?innerOrder='+innerOrder

                        if(url != ''){
                            C.currentWorkPage = staticFunc.openPage((invoiceSortDetail=='FY70001'?"电子资料签收":"纸质资料签收"),url , true );
                        }
                    }
                }
            });

            var importExcelByDgf = Ext.create('Ext.Button', {text: '导入代管费', icon: '../res/img/themes/default/application_go.png', handler: function () {
                    var selRecs = page.getGridBox().getSelectedRecord();
                    var window = Ext.create('Ext.window.Window', {
                        width:400,
                        height:180,
                        layout: 'border',
                        title:CSIS.Lang.ID_109120||"文件上传",
                        modal:true,
                        items: [{
                            xtype:'form',
                            region:'center',
                            layout:{
                                type: 'vbox',
                                align: 'middle'
                            },
                            items:[
                                {
                                    xtype: 'fileuploadfield',
                                    name: 'file',
                                    fieldLabel:CSIS.Lang.ID_109020||'上传附件',
                                    allowBlank: false,
                                    buttonText: CSIS.Lang.ID_109130||'浏览',
                                    margins:'45 45 5 45'
                                },
                                {
                                    xtype: 'label',
                                    name:'infoLabel',
                                    style: {
                                        color:'red'
                                    },
                                    color:'red',
                                    text: CSIS.lang=="EN"?'Upload attachment size cannot exceed 10M':"上传附件的大小不能超过10M",
                                    margins:'10 10'
                                }
                            ]
                        }],
                        buttons: [
                            {
                                text: CSIS.Lang.ID_128700||'模板',
                                handler: function () {
                                    var quotoInputDownProgress = new CSIS.UploadWindow()
                                    quotoInputDownProgress.startDownload("feeInvoice", "代管费导入模板.xlsx");
                                }
                            },
                            "->",
                            {
                                text : CSIS.Lang.ID_109150||'上传',
                                handler : function() {
                                    var form = this.up('window').down('form').getForm();
                                    if (form.isValid()) {
                                        form.submit({
                                            url : '/file/import/feeInvoice?',
                                            waitMsg : CSIS.Lang.ID_109160||'正在上传您的文件，请耐心等候...',
                                            success : function(form,resp) {
                                                Ext.MessageBox.alert(CSIS.Lang.ID_162160||"系统提示",CSIS.Lang.ID_221740||"上传成功");
                                                window.close()
                                            },
                                            failure : function(form,resp) {
                                                Ext.MessageBox.alert(CSIS.Lang.ID_162160||"系统提示", resp.result.msg);
                                            }
                                        });
                                    }
                                }
                            },
                            {
                                text : CSIS.Lang.ID_103820||'取消并关闭',
                                handler : function() {
                                    window.close()
                                }
                            }]
                    });
                    window.show()
                }});

            var copyFeeInvoiceBtn = Ext.create('Ext.Button', {text: '复制发票', icon: '../res/img/themes/default/application_go.png', handler: function () {
                    var selectedRecord = page.getGridBox().getSelectedRecord();
                    if (selectedRecord == null) {
                        Ext.MessageBox.alert("提示", "请选择一条记录！")
                        return;
                    }
                    var receiveMask1 = new Ext.LoadMask(document.body, {msg: "正在处理，请稍候..."});
                    receiveMask1.show();
                    C.ajax.callAction('copyFeeInvoice', 'feeInvoice', {feeInvoiceId:selectedRecord.feeInvoiceId},
                        function (actionName, domainName, resp) {
                            receiveMask1.hide()
                            if (resp.success) {
                                feeInvoiceDomain.getDataSource().reload();
                                Ext.MessageBox.alert("提示", "复制成功");
                            } else {
                                Ext.MessageBox.alert("提示", "复制失败");
                            }
                        })
                }});

            var commitOABtn = Ext.create('Ext.button.Button', {text:'发送到OA', icon: '../res/img/themes/default/accept.png',
                handler: function () {
                    var selectedRecords = page.getGridBox().getCheckedRecords();
                    if (selectedRecords == null || selectedRecords.length==0) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息", CSIS.Lang.ID_103810||"请选择一条记录！");
                        return;
                    }


                    var oaStatus=selectedRecords[0].oaStatus
                    var feeInvoiceId=""
                    var payer=selectedRecords[0].payer
                    var isCommit=true
                    for(var i = 0; i < selectedRecords.length; i++){
                        feeInvoiceId+=selectedRecords[i].feeInvoiceId+","
                        if (selectedRecords[i].oaStatus != oaStatus || oaStatus=='1') {
                            isCommit=false
                        }
                    }

                    if(!isCommit){
                        if(!confirm("所选数据中存在已经发送过OA系统的数据，请确认是否再次发送?")) return false;
                    }

                    if(payer.startWith("1331")){
                        var existAttachMsg = '';
                        C.syncRequest.callAction('getSelectRecordFileList','attachmentFile',{ids:feeInvoiceId},
                            function(action,domainName,resp){
                                if(!resp.success&&resp.msg){
                                    existAttachMsg = resp.msg
                                }
                            });
                        if(!isEmpty(existAttachMsg)){
                            if(!confirm("["+existAttachMsg+"]"+",是否继续操作？")) return false;
                        }
                    }


                    // 发票信息列表数据
                    var feeInvoiceData=[];
                    Ext.each(selectedRecords,function(v){
                        feeInvoiceData.push(v);
                    });

                    feeInvoiceData=Ext.encode(feeInvoiceData)
                    var loadMask = new Ext.LoadMask(document.body, {msg:'发送中...'});
                    Ext.MessageBox.confirm("系统提示", "是否确认发送到OA？", function callback(id) {
                        if (id == 'yes') {
                            loadMask.show();
                            C.ajax.callAction('commitOA', 'feePaymentNotice', {feeInvoiceData:feeInvoiceData},
                                function (actionName, domainName, resp) {
                                 loadMask.hide()
                                if (resp.success) {
                                    Ext.MessageBox.alert("提示", resp.msg);
                                } else {
                                    Ext.MessageBox.alert("提示",resp.msg);
                                }
                            })
                        }else {
                            return
                        }
                    });
                }
            });

            // 化运公司展示发送OA按钮
            if(companyCode&&companyCode.startWith("1331")){
                commitOABtn.show()
            }else {
                commitOABtn.hide()
            }

            //修船、通导、节能减排费用
            function ifSortCheck(invoiceSortCheck) {
                if(invoiceSortCheck=='FY05' || invoiceSortCheck=='FY62' ||invoiceSortCheck=='FY77' ||invoiceSortCheck=='FY78'
                        ||invoiceSortCheck=='FY81'|| invoiceSortCheck=='FY82' ||invoiceSortCheck=='FY83' ||invoiceSortCheck=='FY84'
                        || invoiceSortCheck=='FY85' ||invoiceSortCheck=='FY86' ||invoiceSortCheck=='FY87'||invoiceSortCheck=='FY88'||invoiceSortCheck=='FY98' || invoiceSortCheck=='FY97'){
                    return true;
                }
                return false;
            }
         /*集运检验是否发送sap使用*/
            function checkSYsapInd(selectRecord) {
                var isSuccess = true;
                var msg = ""
                var invoiceSortCheck = selectRecord.invoiceSort
                if(ifSortCheck(invoiceSortCheck)) { //修船、通导、节能减排费用
                    if (isEmpty(selectRecord.innerOrder)) {//如果未填写订单号，则提示“请先选择对应订单，才可以生成付款单”
                        isSuccess = false
                        msg = (CSIS.Lang.ID_237490||"你选择的记录，必须录入订单号才能生成付款通知单！");
                        Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",msg);
                        return isSuccess;
                    }
                    //校验内部订单号是否已经送SAP并且，是否完工日期和发票完工日期一致
                    C.syncRequest.callAction('checkInner','operationRelevance',{vesselCode: selectRecord.vesselCode,orderNO:selectRecord.innerOrder,
                        invoiceSort:selectRecord.invoiceSort,invoiceComDate:Ext.util.Format.date(selectRecord.occurTimeFrom,'Ymd'),
                        invoiceSortDetail:selectRecord.invoiceSortDetail
                    },function(action,domainName,resp){
                        if(!resp || !resp.success){
                            isSuccess = false
                            msg = resp.msg
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",msg);
                        }
                    })
                }
                return isSuccess
            }

            //散运检验是否发送过sap费用类型
            function ifPassSySapSortCheck(invoiceSortCheck,invoiceSortDetailCheck) {
                if(invoiceSortCheck=='FY05' || invoiceSortCheck=='FY61' ||invoiceSortCheck=='FY62' ||(invoiceSortCheck=='FY64'&&invoiceSortDetailCheck=="FY64002")
                        ||invoiceSortCheck=='FY67' ||invoiceSortCheck=='FY97'){
                    return true;
                }
                return false;
            }
            /*散运检验是否发送过sap*/
            function checkPassSySapSend(selectRecord) {
                var isSuccess = true;
                var msg = ""
                var invoiceSortCheck = selectRecord.invoiceSort
                var invoiceSortDetailCheck = selectRecord.invoiceSortDetail
                var payer = selectRecord.payer
                var isAdvanceFee = page.getEditBox().getExtField('isAdvanceFee').getValue();
                var CoscoSap = "";
                C.syncRequest.callAction('getIfSendCoscoSap', 'feeInvoice', {payer: payer},
                        function (action, domainName, resp) {
                            if (resp.success) {
                                var ifSendCoscoSap = resp.msg.split(",")[0];
                                var ifSendSap = resp.msg.split(",")[1];
                                if(ifSendCoscoSap=='1'){  ////中远
                                    CoscoSap = "1"
                                }
                            }
                        });
                if(CoscoSap != "1"){
                    return isSuccess
                }

                if ((payer=='66047200'||payer =='71010000') &&companyCode=='66047200' && selectRecord.occurTimeFrom <new Date(Ext.util.Format.date(new Date(),'Y-07-01'))) {
                        return isSuccess;
                }

                if(!companyCode.startWith("08011100") && ifPassSySapSortCheck(invoiceSortCheck,invoiceSortDetailCheck)) { //费用种类是FY05，FY61,FY62，FY64，FY67，FY69,FY97 , 080111 FY49,FY64
                    if (isEmpty(selectRecord.innerOrder)) {//如果未填写订单号，则提示“请先选择对应订单，才可以生成付款单”
                        isSuccess = false
                        msg = (CSIS.Lang.ID_237490||"你选择的记录，必须录入订单号才能生成付款通知单！");
                        Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",msg);
                        return isSuccess;
                    }

                    //FY64001  FY64003  FY64004  FY64005  FY64006 备件不走修理的查询逻辑
                    if(invoiceSortDetailCheck!="FY64001"&&invoiceSortDetailCheck!="FY64003"&&invoiceSortDetailCheck!="FY64004"&&invoiceSortDetailCheck!="FY64005"&&invoiceSortDetailCheck!="FY64006"){
                        if(isEmpty(isAdvanceFee)||isAdvanceFee=='0'){
                            //校验内部订单号是否已经送SAP
                            C.syncRequest.callAction('checkInnerSapSy','operationRelevance',{vesselCode: selectRecord.vesselCode,orderNO:selectRecord.innerOrder,
                                invoiceSort:selectRecord.invoiceSort,invoiceComDate:Ext.util.Format.date(selectRecord.occurTimeFrom,'Ymd'),
                                invoiceSortDetail:selectRecord.invoiceSortDetail
                            },function(action,domainName,resp){
                                if(!resp || !resp.success){
                                    isSuccess = false
                                    msg = resp.msg
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",msg);
                                }
                            })
                        }
                    }
                }
                return isSuccess
            }

            function checkHyVesselCode(vesselCode,currentPayer,occurTimeFrom,invoiceNo){
                if(youlunFlag&&(vesselCode=='4253'||vesselCode=='9632')&&!isEmpty(occurTimeFrom)){
                    occurTimeFrom = Ext.util.Format.date(occurTimeFrom, 'Y-m-d');
                    var endPayer = "";
                    var endPayerName = "";
                    C.syncRequest.callAction('getVesselManagement','vessel',{vesselCodes:vesselCode,occurTimeFrom:occurTimeFrom} ,function (action, domainName, resp) {
                        endPayer=resp.msg;
                        endPayerName =resp.id;
                    })
                    if(!isEmpty(endPayer)&&endPayer!=currentPayer){
                        Ext.MessageBox.alert("提示信息","选择的记录存在付款单位错误的情况，发票号:"+invoiceNo+"应选择付款单位:"+endPayerName);
                        return false;
                    }
                    return true;
                }
                return true;
            }


            var btnPaymentNotice = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_136640||'生成付款单',icon:'../res/img/themes/default/note_go.png',
                handler:function(){
                    var selectRecord = page.getGridBox().getCheckedRecords();
                    var i = 0;//总记录数
                    var result = validateDataStatus(selectRecord)
                    if(!isEmpty(result)){
                        Ext.MessageBox.alert("",result);
                        return;
                    }
                    result = checkMiscAmount(selectRecord)//addon 190321.
                    if(!result){
                        Ext.MessageBox.alert("","纯运杂费的发票不能和其他类型发票合并生成付款单!");
                        return;
                    }
                    //油运船员费用审核退回付款单用到了该字段，按逻辑该字段不会留到生成付款单时，避免万一情况，这里过滤掉能源公司
                    if(!youlunFlag){
                        result = beforeCreatePaymentnotice(selectRecord)//addon 190321.
                        if(!result){
                            Ext.MessageBox.alert("提示信息","存在疑问状态的发票不能生成付款单!");
                            return;
                        }
                    }

                    // S开头船舶FY7677需要效验内部订单号必填
                    result = validateDataInvoiceNo(selectRecord)//addon 190321.
                    if(!isEmpty(result)){
                        Ext.MessageBox.alert("提示信息",result);
                        return;
                    }
                    if(!isAttachVerified(selectRecord)){
                        return false
                    }

                    //生成付款单时校验，上线税控公司、人民币币种发票、发票号长度是20位，限制税额不能为空为0
                    /*result = validateInvoiceTaxAmount(selectRecord,invoiceCheckCompanyMap);
                    if(!isEmpty(result)){
                        Ext.MessageBox.alert("提示信息","发票号："+result+"，税额不能为空，请检查！");
                        return;
                    }*/

                    //散运的校验逻辑，后需添加维护再该分支下
                    if((companyCode && companyCode.startWith("66")) || (!isEmpty(selectRecord[i].payer) && selectRecord[i].payer.startWith("66"))){
                        var validateBl = true
                        //散运的防疫物品和防海盗费用，增加关联订单校验，且订货标识和费用类别要对应起来
                        validateBl = validateBl ? validateInnerOrder(selectRecord) : false;

                        if(!validateBl){
                            return;
                        }
                    }
                    var validateInnerOrderIds = "";
                    var safeFlag = '';
                    for(var m=0; m<selectRecord.length; m++){
                        if(selectRecord[m].safeFlag=='1' || selectRecord[m].safeFlag){
                            safeFlag = '1';
                            break;
                        }
                    }

                    var vesselName = selectRecord[i].vesselName;
                    var vesselCode1 = selectRecord[i].vesselCode;
                    var feeInvoiceId = selectRecord[i].feeInvoiceId;
                    var invoiceNo = selectRecord[i].invoiceNo;//记录当前发票号
                    var orderNo = selectRecord[i].orderNo
                    var invoiceSort = selectRecord[i].invoiceSort;
                    var freightTypeName = selectRecord[i].freightTypeName;
                    var invoiceSortDetail = selectRecord[i].invoiceSortDetail;
                    var freightName = selectRecord[i].freightName;
                    var payer = selectRecord[i].payer;
                    var payee = selectRecord[i].payee;
                    var payeeName = selectRecord[i].payeeName;
                    var foreStatMonth = Number(new Date(selectRecord[i].foreStatMonth).getFullYear());
                    var confirmUser = selectRecord[i].confirmUser;
                    var currency = selectRecord[i].currency;
                    var currencyName = selectRecord[i].currencyName;
                    var contractNo = selectRecord[i].contractNo;
                    var contractName = selectRecord[i].contractName;
                    var feeAll = Number((selectRecord[i].dtlAmount));//发票含税金额总和
                    var miscAmount =  Number((selectRecord[i].miscAmount))//运杂费
                    var amount = Number((selectRecord[i].amount));//当前发票总金额
                    var dtlAmountSum = Number((selectRecord[i].dtlAmount));//当前发票含税金额总和
                    var ifJigai = selectRecord[i].ifJigai; //库存管理
                    var isFixedAsset = selectRecord[i].isFixedAsset; //是否固定资产
                    var dtlAmountStr = selectRecord[i].dtlAmount;
                    var dtlTaxAmountStr = parseFloat(selectRecord[i].dtlTaxAmount);
                    var orderNo = selectRecord[i].orderNo;
                    var innerOrder = selectRecord[i].innerOrder;
                    var department = selectRecord[i].department;
                    var compType = selectRecord[i].compType;
                    var occurTimeFrom = selectRecord[i].occurTimeFrom;

                    var invoiceNoMap = new C.HashMap();//记录发票号
                    var amountMap = new C.HashMap();//发票含税金额总和
                    var dtlAmountMap = new C.HashMap();//当前发票含税金额总和
                    invoiceNoMap.put(invoiceNo,invoiceNo);
                    amountMap.put(invoiceNo,amount);
                    dtlAmountMap.put(invoiceNo,dtlAmountSum);

                    if(selectRecord.length==1){
                        var returnFlag =  checkHyVesselCode(vesselCode1,payer,occurTimeFrom,invoiceNo);
                       if(!returnFlag) return;
                    }
                    if(companyCode.startWith("0200")&&invoiceSort=='FY01'){
                        var fy01Map = new C.HashMap();
                        fy01Map.put("invoiceNo",selectRecord[i].invoiceNo);   //发票号
                        fy01Map.put("invoiceDate",selectRecord[i].invoiceDate); //发票日期
                        fy01Map.put("amountWithoutTax",selectRecord[i].amountWithoutTax);  //不含税总金额
                        fy01Map.put("taxAmount",selectRecord[i].taxAmount);  //发票总税额
                        fy01Map.put("amount",selectRecord[i].amount); //发票总金额
                        fy01Map.put("dtlAmountWithoutTax",selectRecord[i].dtlAmountWithoutTax); //不含税金额
                        fy01Map.put("dtlTaxAmount",selectRecord[i].dtlTaxAmount);  //税额
                        fy01Map.put("dtlAmount",selectRecord[i].dtlAmount); //含税金额
                        fy01Map.put("baseAmount",selectRecord[i].baseAmount);  //人民币金额
                        var reisNullVerify = verifyIsNullKeFY01(fy01Map,i);
                        if(reisNullVerify==false)return false;
                    }

                    //散运查付款单位的本位币
                    var homeCurrency=""
                    //查询SAP_VESSEL_DGCD
                    var vesselDgcdList = [];
                    if(tianjinFlag){  //散运66和0801
                        C.syncRequest.callAction('list','office',{officeCode:selectRecord[0].payer} ,
                                function (action, domainName, resp) {
                                    if (resp.total > 0) {
                                        homeCurrency= resp.rows[0].homeCurrency;
                                    }
                                }
                        )
                        if(homeCurrency!="CNY"){
                            C.syncRequest.callAction('list','codedict',{'codeType.eq':'SAP_VESSEL_DGCD'} ,
                                    function (action, domainName, resp) {
                                        if (resp.total > 0) {
                                            for(var i=0;resp.rows &&i<resp.rows.length;i++){
                                                vesselDgcdList.push(resp.rows[i].codeValue)
                                            }
                                        }
                                    }
                            )
                        }
                        //用'FY61001','FY61002','FY04021','FY63001','FY64001','FY64002','FY65001'，需校验内部订单号必填。
                        if( isEmpty(selectRecord[i].billNo) && (selectRecord[i].invoiceSortDetail=='FY61001' || selectRecord[i].invoiceSortDetail=='FY61002'||
                                selectRecord[i].invoiceSortDetail=='FY04021' || selectRecord[i].invoiceSortDetail=='FY63001'||
                                selectRecord[i].invoiceSortDetail=='FY64002' || selectRecord[i].invoiceSortDetail=='FY65001' || selectRecord[i].invoiceSortDetail=='FY64011') ){
                            var magAlt
                            if(CSIS.lang=="EN"){
                                magAlt = "When the expense account is '"+selectRecord[i].freightName+"',Internal order Numbers must be filled！"
                            }else{
                                magAlt ="费用科目为"+selectRecord[i].freightName+"时，"+"内部订单号必填！"
                            }
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",magAlt);
                            return;
                        }
                    }

                    //当付款单位为集运及其下属单位时,如果修船、通导、节能减排费用有关联订单，则相关订单要已送ＳＡＰ后才可生成付款单
                    if(!isEmpty(payer) && payer.startWith("68")){
                        var checkPassFirst = checkSYsapInd(selectRecord[0])
                        if(!checkPassFirst)  {
                            return;
                        }
                    }
                    //当付款单位为散运及其下属单位时,如果修船、通导、节能减排费用有关联订单，则相关订单要已送ＳＡＰ后才可生成付款单
                    if(!isEmpty(payer) && payer.startWith("66")){
                        var checkPassSySap = checkPassSySapSend(selectRecord[0])
                        if(!checkPassSySap)  {
                            return;
                        }
                    }
                    if(youlunFlag&&(selectRecord[i].invoiceSort=='FY06'||selectRecord[i].invoiceSort=='ZCF'||selectRecord[i].invoiceSortDetail=='FY01001'||
                            selectRecord[i].invoiceSortDetail=='FY04109')&&isEmpty(selectRecord[i].billNo)){
                        Ext.MessageBox.alert("提示","费用类别为‘技改费、厂修、造船费、厂修油漆费’，关联单号不能为空"); return false;
                    }

                    var isNonOperating = "";
                    if(payer.startWith("08011100") && (invoiceSort=="FY51"  || invoiceSort=="SCF0")){
                        if(!isEmpty(invoiceSortDetail)){
                            C.syncRequest.callAction("list", "freight", {freightCode: invoiceSortDetail},
                                    function (actionName, domainName, resp) {
                                        var result = resp.rows
                                        if (!isEmpty(result) && result.length > 0) {
                                            isNonOperating  = result[0].isNonOperating;
                                        }
                                    });
                        }
                    }

                    i++;//跳到下一条记录  此处有问题，影响下方校验
                    if(innerOrder){
                        validateInnerOrderIds = selectRecord[0].feeInvoiceId + ","
                    }

                    var vesselNameMap = new C.HashMap();//船舶的集合
                    vesselNameMap.put(vesselName,"1");
                    while(selectRecord[i]){
                        if(payer != selectRecord[i].payer){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_115930||"你选择的记录，付款单位不一致，不能合并生成付款单！");
                            return;
                        }
                        if(payee != selectRecord[i].payee || currency != selectRecord[i].currency){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139910||"你选择的记录，开票单位或币种不一致，不能合并生成付款单！");
                            return;
                        }
                        //不同费用大类的发票，不允许制作在同一个付款单。
                        if(invoiceSort != selectRecord[i].invoiceSort){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139911||"你选择的记录，费用大类不一致，不能合并生成付款单！");
                            return;
                        }
                        if(tianjinFlag){  //散运66和0801
                            //1.对散运境外单船公司（付款单位的本位币是USD）船舶，业务用户在航标系统录入账单时，需增加只能单船制作付款单。散运查付款单位的本位币
                            if(homeCurrency!='CNY' && vesselCode1 != selectRecord[i].vesselCode
                                    &&vesselDgcdList.indexOf(vesselCode1)!=-1){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_139912||"当前付款单位为境外公司,不同船舶不能合并生成付款单！");
                                return;
                            }
                        }
                        if(youlunFlag||sanyunFlag||payer.startWith("65")||payer.startWith("91")){
                            if(selectRecord[i].ifJigai != ifJigai){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_237470||"所选的发票包含了存货和非存货的，不能一起生成付款单！");
                                return;
                            }
                            if(selectRecord[i].isFixedAsset != isFixedAsset){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_237480||"所选的发票包含了固定资产和非固定资产的，不能一起生成付款单");
                                return;
                            }
                            if(youlunFlag){
                                if(companyCode.substring(0,4)=='0811'&&selectRecord[i].invoiceSort =='FY60'&&invoiceSort=='FY60'){//0811船员薪酬不做合并限制
                                }else if((selectRecord[i].invoiceSort != invoiceSort||selectRecord[i].invoiceSortDetail != invoiceSortDetail)){
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","所选的发票的费用类别和费用科目不一致，不能合并生成付款单");
                                    return;
                                }
                                //修理通导技改流程的才做勾选发票所属船舶团队不同的 校验
                                if( selectRecord[i].invoiceSort=='FY06' || selectRecord[i].invoiceSortDetail=='FY01007' ||
                                    ( (selectRecord[i].invoiceSort == "FY01" ) && selectRecord[i].invoiceSortDetail != "FY01004" )) {
                                    if (selectRecord[i].department != department) {
                                        Ext.MessageBox.alert(CSIS.Lang.ID_100781 || "信息", "勾选发票所属船舶团队不同，请重新选择。");
                                        return;
                                    }
                                }
                                if((selectRecord[i].invoiceSort=='FY06'||selectRecord[i].invoiceSort=='ZCF'||selectRecord[i].invoiceSortDetail=='FY01001'||
                                        selectRecord[i].invoiceSortDetail=='FY04109')&&isEmpty(selectRecord[i].billNo)){
                                    Ext.MessageBox.alert("提示","费用类别为‘技改费、厂修、造船费、厂修油漆费’，关联单号不能为空"); return false;
                                }
                                var returnFlag = checkHyVesselCode(selectRecord[i].vesselCode,payer,selectRecord[i].occurTimeFrom,selectRecord[i].invoiceNo);
                                if(!returnFlag) return;
                            }
                        }
                        if(youlunFlag&&(payer.startWith('0806')||payer.startWith('08024400'))){
                            if (selectRecord[i].vesselCode != vesselCode1) {
                                Ext.MessageBox.alert( "信息", "选择的船舶不一致，不能生成付款单。");
                                return;
                            }
                        }

                        if(payer.startWith("08011100") && (selectRecord[i].invoiceSort=="FY51"  || selectRecord[i].invoiceSort=="SCF0")){
                            var falg = true;
                            if(!isEmpty(selectRecord[i].invoiceSortDetail)) {
                                C.syncRequest.callAction("list", "freight", {freightCode: selectRecord[i].invoiceSortDetail},
                                    function (actionName, domainName, resp) {
                                        var result = resp.rows
                                        if (!isEmpty(result) && result.length > 0) {
                                            var row = result[0];
                                            if (isNonOperating!=row.isNonOperating) {
                                                falg = false;
                                            }
                                        }
                                });
                            }
                            if(!falg){
                                Ext.MessageBox.alert("提示", "经营类的（到航次港口的）费用和非经营类的费用不可以生成在同一个付款单，请检查勾选的项目！");
                                return;
                            }
                        }
                        if(!isEmpty(selectRecord[i].vesselName)){
                            if(isEmpty(vesselNameMap.get(selectRecord[i].vesselName))){
                                vesselNameMap.put(selectRecord[i].vesselName,"1");
                            }
                        }

                        if(selectRecord[i].innerOrder){
                            validateInnerOrderIds = validateInnerOrderIds + selectRecord[i].feeInvoiceId + ","
                        }

                        if(companyCode.startWith("0200")&&selectRecord[i].invoiceSort=='FY01'){
                            var fy01Map = new C.HashMap();
                            fy01Map.put("invoiceNo",selectRecord[i].invoiceNo);   //发票号
                            fy01Map.put("invoiceDate",selectRecord[i].invoiceDate); //发票日期
                            fy01Map.put("amountWithoutTax",selectRecord[i].amountWithoutTax);  //不含税总金额
                            fy01Map.put("taxAmount",selectRecord[i].taxAmount);  //发票总税额
                            fy01Map.put("amount",selectRecord[i].amount); //发票总金额
                            fy01Map.put("dtlAmountWithoutTax",selectRecord[i].dtlAmountWithoutTax); //不含税金额
                            fy01Map.put("dtlTaxAmount",selectRecord[i].dtlTaxAmount);  //税额
                            fy01Map.put("dtlAmount",selectRecord[i].dtlAmount); //含税金额
                            fy01Map.put("baseAmount",selectRecord[i].baseAmount);  //人民币金额
                            var reisNullVerify = verifyIsNullKeFY01(fy01Map,i);
                            if(reisNullVerify==false)return false;
                        }

                        //计算发票金额、关联信息金额和税额
                        feeInvoiceId+=','+selectRecord[i].feeInvoiceId
                        feeAll += Number(selectRecord[i].dtlAmount);
                        miscAmount += Number(selectRecord[i].miscAmount);

                        //拼接字符串，验证相关字段
                        dtlAmountStr += ","+selectRecord[i].dtlAmount;
                        dtlTaxAmountStr += ","+parseFloat(selectRecord[i].dtlTaxAmount);

                        invoiceNo = selectRecord[i].invoiceNo;//重新记录当前发票金额为新发票金额
                        invoiceNoMap.put(invoiceNo,invoiceNo);
                        if(dtlAmountMap.containsKey(invoiceNo)){
                            dtlAmountMap.put(invoiceNo,(dtlAmountMap.get(invoiceNo)+Number(selectRecord[i].dtlAmount)));
                        }else{
                            dtlAmountMap.put(invoiceNo,Number(selectRecord[i].dtlAmount));
                        }
                        amountMap.put(invoiceNo, Number((selectRecord[i].amount)));

                        //当付款单位为集运及其下属单位时,如果修船、通导、节能减排费用有关联订单，则相关订单要已送ＳＡＰ后才可生成付款单
                        if(!isEmpty(payer) && (payer.startWith("68")||payer.startWith("01"))){
                            var checkPass = checkSYsapInd(selectRecord[i])
                            if(!checkPass)  {
                                return;
                            }
                        }
                        //当付款单位为散运及其下属单位时,如果修船、通导、节能减排费用有关联订单，则相关订单要已送ＳＡＰ后才可生成付款单
                        if(!isEmpty(payer) && (payer.startWith("66") || payer.startWith("08011100"))){
                            var checkPassSySap1 = checkPassSySapSend(selectRecord[i])
                            if(!checkPassSySap1)  {
                                return;
                            }
                        }

                        if(compType != selectRecord[i].compType){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","你选择的记录，商务费用与非商务费用不能合并生成付款单！");
                            return;
                        }
                        i++;
                    }

                    var km=0;
                    while(selectRecord[km]){
                        if ((selectRecord[km].ifJigai || selectRecord[km].ifJigai == '1') && (companyCode.startWith("65")||companyCode.startWith("91")||companyCode.startWith("63"))) {
                            var payerErrorFlag = false;
                            C.syncRequest.callAction('list','operationRelevance',{_extend:" AND mtbl.feeInvoiceId = '"+selectRecord[km].feeInvoiceId+"' " +
                                    " and (exists (select 1 from ApplyConfirm c where c.applyConfirmId = mtbl.applyConfirmId and c.principalGroupCode <> '"+selectRecord[km].payer+"')" +
                                    " or exists (select 1 from ApplyConfirmMtr m where m.applyConfirmMtrId = mtbl.applyConfirmId and m.principalGroupCode <> '"+selectRecord[km].payer+"'))"} ,
                                function (action, domainName, resp){
                                    if (resp && resp.rows && resp.rows.length > 0) {
                                        payerErrorFlag = true;
                                        Ext.MessageBox.alert(CSIS.Lang.ID_100780 || "信息", "发票："+selectRecord[km].invoiceNo+"付款单位和订单中付款单位不一致");
                                    }
                                });
                            if (payerErrorFlag) {
                                return false;
                            }
                        }

                        if(youlunFlag&&(selectRecord[km].invoiceSort=='FY06'||selectRecord[km].invoiceSortDetail=='FY01001'||selectRecord[km].invoiceSortDetail=='FY04109')&&!isEmpty(selectRecord[km].vesselCode)&&!isEmpty(selectRecord[km].invoiceSortDetail)&&!isEmpty(selectRecord[km].foreStatMonth)){
                            var isExistBillNo=true; var extistBillNoMsg="";
                            C.syncRequest.callAction('checkInnerOrderNoIsCorrect','jgInnerOrder',{year:selectRecord[km].foreStatMonth,vesselCode:selectRecord[km].vesselCode,innerOrder:selectRecord[km].billNo,isStrike:selectRecord[km].isStrike,
                                invoiceSort:selectRecord[km].invoiceSort,invoiceSortDetail:selectRecord[km].invoiceSortDetail},function(action,domainName,resp){
                                if(resp){ isExistBillNo =resp.success;  extistBillNoMsg = resp.msg; }
                            })
                            if(!isExistBillNo){
                                Ext.MessageBox.alert("提示","第"+(km+1)+"条发票记录"+extistBillNoMsg); return false;
                            }
                        }
                        km++;
                    }
                    if(payer!='71010000'){  //付款单位不是71010000的船不做以下的验证
                        var isSuccess = true;
                        var msg = ""
                        if(!isEmpty(invoiceNoMap.keys().toString())){
                            C.syncRequest.callAction('verifyAmount','feeInvoice',{invoiceNos:invoiceNoMap.keys().toString(),payee:payee,payer:payer},function(action,domainName,resp){
                                if(!resp || !resp.success){
                                    isSuccess = false
                                    msg = resp.msg
                                }
                            })
                        }
                        if(!isSuccess){
                            Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",msg);
                            return;
                        }
                        //验证多条发票的发票总金额和含税金额总和是否匹配
                        var invoiceNoStr = ''
                        Ext.each(dtlAmountMap.keys(),function(v){
                            if(dtlAmountMap.get(v).toFixed(2)!=amountMap.get(v).toFixed(2)){
                                isSuccess = false
                                invoiceNoStr+=v+','
                            }
                        });
                        if(!isSuccess){
                            if(youlunFlag&&isEmpty(invoiceNoMap.keys().toString())){  //发票号不为空
                            }else{
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息","所选发票号["+invoiceNoStr.substring(0,invoiceNoStr.length-1)+"]的总金额和发票的明细金额不一致，请选择完整后再生成付款单!");
                                return;
                            }
                        }
                        //验证关联信息和业务金额税额、固定资产也许验证
                        if(ifJigai||isFixedAsset){
                            isSuccess = true;
                            msg = ""
                            C.syncRequest.callAction('checkStoraged','operationRelevance',{feeInvoiceId:feeInvoiceId,amount:dtlAmountStr,taxAmount:dtlTaxAmountStr,num:i},function(action,domainName,resp){
                                if(!resp || !resp.success){
                                    isSuccess = false
                                    msg = resp.msg
                                }
                            })
                            if(!isSuccess){
                                switch(msg){
                                    case "-1" : Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_139980||"系统发生异常，请联系管理员!");return;
                                    case "1" : Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_139990||"发票金额和关联信息的业务金额和不一致!");return;
                                    case "2" : Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140000||"发票税额和关联信息的业务税额和不一致!");return;
                                    case "3" : Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140010||"发票关联信息中存在未审核记录!");return;
                                }
                            }
                        }
                    }

                    //特运的备件费需要加已签收且审核通过才能生成付款单
                    if(companyCode&&companyCode.startWith("65")){
                        var msg = "";
                        var flag = false;

                            if (invoiceSort=="FY63"||invoiceSort=="FY04"||invoiceSort=="FY66"||invoiceSort=="FY65"||invoiceSort=="FY34"||
                                (invoiceSort == 'FY64'&&(invoiceSortDetail=='FY64005'||invoiceSortDetail=='FY64006'))) {
                                Ext.each(selectRecord,function(v){
                                    if (!(Number(v.dtlAmount)==Number(v.miscAmount) || Number(v.dtlAmount) < 0)) {
                                        C.syncRequest.callAction('list','operationRelevance',{feeInvoiceId:v.feeInvoiceId},function(action,domainName,resp){
                                            if (!(resp&&resp.rows&&resp.rows.length > 0)) { msg += v.invoiceNo + "," }
                                        })
                                    }
                                })
                            } else if (invoiceSort == 'FY61'||invoiceSort == 'FY62'||invoiceSort == 'FY05'||invoiceSort == 'FY28'||invoiceSort == 'FY67'||
                                (invoiceSort == 'FY64'&&(invoiceSortDetail=='FY64003'||invoiceSortDetail=='FY64004'))|| bndFlag) {
                                Ext.each(selectRecord,function(v){
                                    if (!(Number(v.dtlAmount)==Number(v.miscAmount) || Number(v.dtlAmount) < 0)&&!isEmpty(v.innerOrder)) {
                                        var innerOrders = v.innerOrder.split(",");
                                        for (i = 0; i < innerOrders.length; i++) {//isInvoice
                                            var requestDomain = 'completionReportVo';
                                            if (invoiceSort == 'FY28') {//ifPaidAll
                                                requestDomain = 'applyConfirmMtrVo'
                                            } else if (bndFlag) {//billStatus
                                                requestDomain = 'bandApplyConfirm';
                                            }
                                            if (invoiceSort != 'FYRG') {
                                                C.syncRequest.callAction('list',requestDomain,{'applyNo.eq':innerOrders[i]},function(action,domainName,resp){
                                                    if ((resp&&resp.rows&&resp.rows.length > 0)) {
                                                        if (resp.rows[0].isInvoice == '2' || (invoiceSort == 'FY28'&&resp.rows[0].ifPaidAll == '2') || (bndFlag&&resp.rows[0].billStatus == '2')) {
                                                            C.syncRequest.callAction('list','operationRelevance',{'relateOrderNo.eq':innerOrders[i]},function(action,domainName,resp){
                                                                if (!(resp&&resp.rows&&resp.rows.length > 0)) { msg += v.invoiceNo+ "【"+ innerOrders[i] +"发票已来齐】" + "," }
                                                            })
                                                        }
                                                    }
                                                })
                                            }

                                        }
                                    }
                                })
                            }
                            if(flag){
                                Ext.MessageBox.alert("提示信息", "存在境外采购的订单，不予生成付款单");
                                return false;
                            }
                            if(!isEmpty(msg)){
                                msg = msg.substring(0,msg.length-1)
                                Ext.MessageBox.alert("信息","发票号("+msg+")未关联订单信息，不能生成付款单，请核查！");
                                return
                            }

                    }
                    else if(companyCode&&companyCode.startWith("91")){
                        if (!(invoiceSort=="FY63"||invoiceSort=="FY04")) {
                            var msgtext = "";
                            Ext.each(selectRecord,function(v){
                                C.syncRequest.callAction('list','operationRelevance',{feeInvoiceId:v.feeInvoiceId},function(action,domainName,resp){
                                    if (!(resp&&resp.rows&&resp.rows.length > 0)) {
                                        msgtext += v.invoiceNo + "," ;
                                    }
                                });
                            });
                            if(!isEmpty(msgtext)){
                                msgtext = msgtext.substring(0,msgtext.length-1);
                                Ext.MessageBox.alert("系统提示","发票号("+msgtext+")未关联订单信息，不能生成付款单，请核查！");
                                return
                            }
                        }
                    }


                    //68的备件费需要加全部签收完成验证
                    if(companyCode&&companyCode.startWith("68")&&invoiceSort=="FY63"){
                        var msg = ""
                        Ext.each(selectRecord,function(v){
                            if(v.innerOrder){
                                C.syncRequest.callAction('listSearch','applyConfirm',{applyNo: v.innerOrder},function(action,domainName,resp){
                                    if(resp && resp.rows && resp.rows.length>0){
                                        if(resp.rows[0].applyStatus && resp.rows[0].applyStatus!="28"){
                                            msg += v.innerOrder + ","
                                        }
                                    }
                                })
                            }
                        })
                        if(!isEmpty(msg)){
                            msg = msg.substring(0,msg.length-1)
                            Ext.MessageBox.alert("信息","该订单("+msg+")未全部签收，不能生成付款单，请核查！");
                            return
                        }
                    }

                    //68的航修费需要加是否已存在该订单号的付款单，如果有不能再生成付款单
                    if(companyCode&&companyCode.startWith("68")&&(invoiceSort=="FY62"||invoiceSort=="FY05")){
                        var msg = ""
                        Ext.each(selectRecord,function(v){
                            if(v.innerOrder){
                                C.syncRequest.callAction('getIsCreateFeePaymentNotice','feePaymentNotice',{innerOrder: v.innerOrder},function(action,domainName,resp){
                                    if(!resp.success){
                                        msg += v.innerOrder + ","
                                    }
                                })
                            }
                        })
                        if(!isEmpty(msg)){
                            msg = msg.substring(0,msg.length-1)
                            Ext.MessageBox.alert("信息","该订单("+msg+")相关发票已生成付款单，不能重复生成付款单，请核查！");
                            return
                        }
                    }

                    //如果付款单位是66或0801开头没并且费用类别是- 并且是送中远SAP 效验订单号或者关联信息必须存在一种
                    if((payer.startWith("66")||payer.startWith("0801"))&&(invoiceSort=="FY04"||invoiceSort=="FY05"||invoiceSort=="FY33"
                            ||invoiceSort=="FY61"||invoiceSort=="FY62"||invoiceSort=="FY63"||invoiceSort=="FY64"
                            ||invoiceSort=="FY65"||invoiceSort=="FY66"||invoiceSort=="FY67"||invoiceSort=="FY97")){
                        var CoscoSap = "";
                        C.syncRequest.callAction('getIfSendCoscoSap', 'feeInvoice', {payer: payer},
                                function (action, domainName, resp) {
                                    var ifSendCoscoSap = resp.msg.split(",")[0];
                                    var ifSendSap = resp.msg.split(",")[1];
                                    if (resp.success) {
                                        if(ifSendCoscoSap=='1'){  ////中远
                                            CoscoSap = "1"
                                        }
                                    }
                                });
                        if(!isEmpty(CoscoSap)){
                            var vlMsg = ""
                            for(var j=0;j <selectRecord.length;j ++){
                                var vlRecord = selectRecord[j]
                                if(isEmpty(vlRecord.innerOrder)&&vlRecord.projectName!="已挂单"){
                                    vlMsg += vlRecord.invoiceNo + "、"
                                }
                            }
                            if(!isEmpty(vlMsg)){
                                if(payer.startWith("0801")){
                                    if(!confirm("发票"+vlMsg+"的订单号不存在，是否选择订单号后再生成付款单！\n继续点确定，否则请点取消按钮。")){
                                        return false;
                                    }
                                }else{
                                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "发票"+vlMsg+"的订单号与关联信息不能全部不存在，请选择订单号或者关联信息后再生成付款单！");
                                    return;
                                }
                            }
                        }
                    }

                    if(validateInnerOrderIds){
                        validateInnerOrderIds = validateInnerOrderIds.substring(0,validateInnerOrderIds.length-1)
                        if(invoiceSort == 'FY01'||invoiceSort == 'FY02'||invoiceSort == 'FY63'||invoiceSort == 'FY64'){
                            var validateInnerOrderMsg = ""
                            if(invoiceSortDetail == 'FY01003'||invoiceSortDetail == 'FY01004'||invoiceSortDetail == 'FY64001'||
                                    invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004' ||invoiceSort== 'FY63'){//备件订购
                                C.syncRequest.callAction('validateInnerOrder','feeInvoice',{feeInvoiceId: validateInnerOrderIds,modular:"BJ"},function(action,domainName,resp){
                                    if(!resp.success){
                                        validateInnerOrderMsg = resp.msg
                                    }
                                })
                            }
                            if(!isEmpty(validateInnerOrderMsg)){
                                Ext.MessageBox.alert("信息",validateInnerOrderMsg);
                                return
                            }
                        }else if(invoiceSort=='FY04'||invoiceSort =='FY34'||invoiceSort=='FY33'||invoiceSort=='FY65'||invoiceSort=='FY66'
                                ||invoiceSort=='FY72'||invoiceSort=='FY76'||invoiceSort=='FY58'||invoiceSort=='FY73'||invoiceSort=='FY74'
                                ||invoiceSort=='FY75'||(invoiceSort=='FY16'&&invoiceSortDetail=='FY16006')){
                            var validateInnerOrderMsg = ""
                            C.syncRequest.callAction('validateInnerOrder','feeInvoice',{feeInvoiceId: validateInnerOrderIds,modular:"WL"},function(action,domainName,resp){
                                if(!resp.success){
                                    validateInnerOrderMsg = resp.msg
                                }
                            })
                            if(!isEmpty(validateInnerOrderMsg)){
                                Ext.MessageBox.alert("信息",validateInnerOrderMsg);
                                return
                            }
                        }
                    }

                    var vesselNameStr = "";
                    Ext.each(vesselNameMap.keys(),function(v){
                        vesselNameStr+=(v+",");
                    });
                    if(!isEmpty(vesselNameStr)){
                        vesselNameStr = vesselNameStr.substring(0,vesselNameStr.length-1);
                    }
debugger
                    if(companyCode&&companyCode.startWith("68")){
                        //集运只有备件物料开通校验订单金额功能
                        if(invoiceSort=='FY04'||invoiceSort =='FY34'||invoiceSort=='FY33'||invoiceSort=='FY65'||invoiceSort=='FY66'
                            ||invoiceSort=='FY72'||invoiceSort=='FY76'||invoiceSort=='FY58'||invoiceSort=='FY73'||invoiceSort=='FY74'
                            ||invoiceSort=='FY75'||(invoiceSort=='FY16'&&invoiceSortDetail=='FY16006') || invoiceSortDetail == 'FY01003'||
                            invoiceSortDetail == 'FY01004'||invoiceSortDetail == 'FY64001'||
                            invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004' ||invoiceSort== 'FY63') {
                            var msg = "";
                            C.syncRequest.callAction('validateInnerOrderAndSignNo','validateInvoiceAndOrder',{feeInvoiceId:feeInvoiceId},function(a,d,resp){
                                if(!resp.success){
                                    msg = resp.msg;
                                }
                            });
                            if(msg){
                                Ext.MessageBox.alert("信息",msg);
                                return
                            }
                        }
                    }

                    C.context.register('feeInvocieParm',{
                        feeInvoiceId:feeInvoiceId,
                        orderNo:orderNo,
                        vesselCode:vesselCode1,
                        vesselName:vesselName,
                        vesselNameStr:vesselNameStr,
                        invoiceSort:invoiceSort,
                        freightTypeName:freightTypeName,
                        invoiceSortDetail:invoiceSortDetail,
                        freightName:freightName,
                        payer :payer,
                        payee :payee,
                        payeeName :payeeName,
                        foreStatMonth :foreStatMonth,
                        confirmUser :confirmUser,
                        currency :currency,
                        currencyName:currencyName,
                        contractNo:contractNo,
                        contractName:contractName,
                        isFixedAsset:isFixedAsset,
                        allAmount:feeAll,
                        miscAmount:miscAmount,//add on 190321
                        ifJigai:ifJigai,
                        safeFlag:safeFlag,
                        compType:compType,
                        occurTimeFrom:occurTimeFrom});

                    if(orderNo){  //如果发票里有付款单号，说明曾经生成过付款单，可能被删除了。现在重新生成付款单，要询问用户是否是用原来的付款单号
                        //查询付款单，存在则生成新的付款单号
                        C.ajax.callAction('list','feePaymentNotice',{paymentNo:orderNo},function(action,domainName,resp){
                            if(resp && resp.rows && resp.rows.length>0){ //存在重复单号直接生成新付款单
                                createNewPaymentNoAndShowWindow(invoiceSort);
                            } else{ //不存在重复单号
                                Ext.Msg.confirm(CSIS.Lang.ID_162160||'系统提示',(CSIS.Lang.ID_140020||'是否使用原付款单号')+orderNo+'?',function(btn){
                                    if(btn == 'yes'){
                                        showPaymentNoticeWindow(orderNo)
                                    }
                                    if(btn == 'no'){
                                        createNewPaymentNoAndShowWindow(invoiceSort);
                                    }
                                })
                            }
                        });
                    }else{
                        createNewPaymentNoAndShowWindow(invoiceSort);
                    }
                }
            });

            function validateInnerOrder(selectRecord){
                var validateBl = true
                var feeInvoiceIds = "";
                for(var s=0; s<selectRecord.length; s++){
                    if((selectRecord[s].invoiceSort=="FY04"&&(selectRecord[s].invoiceSortDetail=="FY04107"))||selectRecord[s].invoiceSort=="FY43"){
                        if(isEmpty(selectRecord[s].innerOrder)){
                            validateBl = false
                            Ext.MessageBox.alert("信息","发票："+selectRecord[s].invoiceNo+" 订单号不能为空！");
                            break;
                        }else{
                            feeInvoiceIds += selectRecord[0].feeInvoiceId + ","
                        }
                    }
                }
                if(feeInvoiceIds){
                    feeInvoiceIds = feeInvoiceIds.substring(0,feeInvoiceIds.length-1)
                    C.syncRequest.callAction('validateInnerOrderSy','feeInvoice', {ids:feeInvoiceIds,companyCode:"66000000"},
                            function(action,domainName,resp){
                                if(!resp.success){
                                    validateBl = false
                                    Ext.MessageBox.alert("信息",resp.msg);
                                }
                            }
                    );
                }

                return validateBl;
            }

            function createNewPaymentNoAndShowWindow(invoiceSort){
                C.ajax.callAction('getSeq','feePaymentNotice',{type:invoiceSort.substring(0,1)},function(action,domainName,resp){
                    if(resp.success){
                        showPaymentNoticeWindow(resp.msg,invoiceSort);
                    } else{
                        C.context.unRegister('feeInvocieParm');
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",resp.msg);
                    }
                });
            }
            function getVovayeInfo() {
                if (isCreate || isEdit) {
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                    var vesselName = page.getEditBox().getExtField("vesselCode").getComboValue().display;
                    var occurTimeFrom = page.getEditBox().getExtField('occurTimeFrom').getValue();
                    var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                    if (invoiceSort == 'FYR1') {
                        if (!isEmpty(vesselCode) && !isEmpty(occurTimeFrom)) {
                            C.syncRequest.callAction('getVoyageIfo', 'feeInvoice', {
                                    vesselCode: vesselCode,
                                    occurTimeFrom: occurTimeFrom
                                },
                                function (action, domainName, resp) {
                                    if (resp.extend) {
                                        page.getEditBox().getExtField("portCode").setComboValue(resp.extend.port, resp.extend.portName)
                                        page.getEditBox().getExtField("voyageNo").setValue(resp.extend.voyage)
                                        if(!isEmpty(resp.extend.msg)&&youlunFlag){
                                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",vesselName+resp.extend.msg);
                                        }
                                    }
                                });
                        }
                    }
                }
            }
            function showPaymentNoticeWindow(seq,invoiceSort){
                var windowBox = new C.WindowBox({title:CSIS.Lang.ID_136640||'生成付款单',height:320,width:900});
                C.context.get('feeInvocieParm').seq = seq;
                C.context.get('feeInvocieParm').wBox = windowBox.getUI();
                C.context.get('feeInvocieParm').parmaFlag = "feeinvoice";  //区分是哪个界面调用
                windowBox.addListener('closed',function(){
                    var stores = page.getGrid().getSelectionModel().getSelection();
                    var feeInvocieBackParam = C.context.get('feeInvocieBackParam');
                    C.context.unRegister('feeInvocieBackParam');
                    if(feeInvocieBackParam){
                        Ext.each(stores,function(v){
                            v.set('paymentNoticeId',feeInvocieBackParam.paymentNoticeId);
                            v.set('orderNo',seq);
                            v.set('invoiceStatus','3');
                            v.commit();
                        });
                        page.getToolbarBox().getButton("edit").setDisabled(true);
                        page.getToolbarBox().getButton("remove").setDisabled(true);
                        setButtonStatus('payNoti',false);
                        setButtonStatus('opera',false);
                        printBtn.setDisabled(false);
                        infoPrintBtn.setDisabled(false);
                    }
                });
                var payer = C.context.get('feeInvocieParm').payer;
                var payerCurrency = ""; //add on 230609
                C.syncRequest.callAction('getBaseCurrency', 'vwCrmBankInfo', {payer: payer}, function (action, domainName, resp) {
                    if(resp.success){
                        payerCurrency = resp.msg
                    }
                });

                if(payer=='71010000'){
                    var feeAll = C.context.get('feeInvocieParm').allAmount;
                    Ext.Msg.confirm(CSIS.Lang.ID_162160||'系统提示',CSIS.format(CSIS.Lang.ID_242570||'发票的总金额是{1},确认继续,否返回',feeAll),function(btn){
                        if(btn == 'no'){
                            return;
                        }else{
                            windowBox.loadPage('fmm/feeInvoicePaymentNotice.jsp');
                            C.currentWorkPage = windowBox.getUI();
                            windowBox.getUI().show();
                        }
                    })
                }else if(companyCode=='66000000' || payer=='66030000'){//add on 230509
                    windowBox = new C.WindowBox({title:CSIS.Lang.ID_136640||'生成付款单',height:500,width:900});
                    C.context.get('feeInvocieParm').wBox = windowBox.getUI();
                    windowBox.loadPage('fmm/feeInvoicePaymentNoticeSanYun.jsp');
                    C.currentWorkPage = windowBox.getUI();
                    windowBox.getUI().show();
                }else{
                    windowBox.loadPage('fmm/feeInvoicePaymentNotice.jsp');
                    C.currentWorkPage = windowBox.getUI();
                    windowBox.getUI().show();
                }
            }

            var btnOperation_sub = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_140030||'关联信息',icon:'../res/img/themes/default/arrow_divide_left.png',
                        handler:function(){
                            Ext.getElementById(btnOperation.getId()).click()
                        }
                    });
            var btnOperation = Ext.create('Ext.button.Button',
                    {text:CSIS.Lang.ID_140030||'关联信息',icon:'../res/img/themes/default/arrow_divide_left.png',
                        handler:function(){
                            var selectR = page.getGridBox().getCheckedRecords();
                            var msg = btnOperationBtnVaidate(selectR)
                            if(msg!=""&&msg.length>1){
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_140040||"只能选择一条记录！");
                            }else{
                                var selectRecord = selectR[0];
                                var url = "";
                                var title = "";
                                var classNo = "";
                                var className = "";
                                //付款单位，用于弹出关联信息框
                                var payer = selectRecord.payer;
                                C.context.register('payer',payer);
                                if(selectRecord.invoiceSort == 'FY01'||selectRecord.invoiceSort == 'FY02' ||selectRecord.invoiceSort == 'FY62'||selectRecord.invoiceSort == 'FY61'
                                        ||selectRecord.invoiceSort == 'FY63' ||selectRecord.invoiceSort == 'FY64' ||selectRecord.invoiceSort == 'FY67' || selectRecord.invoiceSort == 'FY05' || selectRecord.invoiceSort == 'FY69'
                                        || selectRecord.invoiceSort == 'FY97'||selectRecord.invoiceSort == 'FY56'){
                                    if(selectRecord.invoiceSortDetail == 'FY01003'||selectRecord.invoiceSortDetail == 'FY01004'||selectRecord.invoiceSortDetail == 'FY64001'||
                                            selectRecord.invoiceSortDetail == 'FY02003'||selectRecord.invoiceSortDetail == 'FY02004'|| selectRecord.invoiceSort == 'FY63'|| selectRecord.invoiceSortDetail == 'FY56001'){
                                        url = 'fmm/vwFmmSpsPurchaseQuery.jsp';
                                        title = (CSIS.Lang.ID_237500||"关联信息(备件)");
                                    }else if(selectRecord.invoiceSortDetail == 'FY01002' || selectRecord.invoiceSortDetail == 'FY01005'|| selectRecord.invoiceSortDetail == 'FY01007'
                                            || selectRecord.invoiceSort == 'FY62' || selectRecord.invoiceSort == 'FY67' || selectRecord.invoiceSort == 'FY97'|| selectRecord.invoiceSortDetail == 'FY56002'|| selectRecord.invoiceSortDetail == 'FY56003'){
                                        if(companyCode&&companyCode.startWith("91")){
                                            url = 'fmm/vwFmmVrmCompletionQueryNew.jsp';
                                            title = (CSIS.Lang.ID_237530 || "关联信息(修理)");
                                        } else if (companyCode&&companyCode.startWith("65")) {
                                            url = 'fmm/vwFmmVrmCompletionQuery.jsp';
                                            title = (CSIS.Lang.ID_237530 || "关联信息(修理)");
                                        } else {
                                            url = 'fmm/vwFmmVrmShipGuideQuery.jsp';
                                            title = (CSIS.Lang.ID_237520||"关联信息(航修通导)");
                                        }
                                    } else if (companyCode.startWith('65')&&(selectRecord.invoiceSortDetail == 'FY64005' || selectRecord.invoiceSortDetail == 'FY64006')) {
                                        if (selectRecord.invoiceSortDetail == 'FY64005') {
                                            url = 'fmm/vwFmmSpsPurchaseQuery.jsp';
                                            title = (CSIS.Lang.ID_237500||"关联信息(备件)");
                                        } else if (selectRecord.invoiceSortDetail == 'FY64006') {
                                            url = 'fmm/vwFmmMtrPurchaseQuery.jsp';
                                            title = (CSIS.Lang.ID_237540||"关联信息(物料)");
                                        }
                                    }else{
                                        if(companyCode&&companyCode.startWith("91")){
                                            url = 'fmm/vwFmmVrmCompletionQueryNew.jsp';
                                            title = (CSIS.Lang.ID_237530 || "关联信息(修理)");
                                        }else {
                                            url = 'fmm/vwFmmVrmCompletionQuery.jsp';
                                            title = (CSIS.Lang.ID_237530 || "关联信息(修理)");
                                        }
                                    }
                                }else if(selectRecord.invoiceSort=='FY04'||selectRecord.invoiceSort=='FY34'||selectRecord.invoiceSort=='FY33'
                                        || selectRecord.invoiceSort=='FY65'||selectRecord.invoiceSort=='FY66'||selectRecord.invoiceSort=='FY58'
                                        ||(selectRecord.invoiceSort=='FY16'||selectRecord.invoiceSortDetail=='FY16006')){
                                    url = 'fmm/vwFmmMtrPurchaseQuery.jsp';
                                    title = (CSIS.Lang.ID_237540||"关联信息(物料)");
                                    if(companyCode.substring(0,2)=='66'){
                                        C.context.register('companyParma',{flag:'66'}) ;

                                    }
                                    if(selectRecord.invoiceSort=='FY16'&&selectRecord.invoiceSortDetail=='FY16006'){
                                        //费用类别FY16科目FY16006弹物料弹出框，查询默认限制劳保用品的订货标示50
                                        C.context.register('isDefaultOrderType',{orderType:"50",orderTypeName:"劳保用品"});
                                    }
                                    if(selectRecord.invoiceSort == 'FY65'){
                                        classNo = '25'
                                        className = (CSIS.Lang.ID_140050||'油漆');
                                    }
                                    if(selectRecord.invoiceSort == 'FY66'){
                                        classNo = 'COSCO93'
                                        className = (CSIS.Lang.ID_140060||'化学品');
                                    }
                                    if(selectRecord.invoiceSort == 'FY33'){
                                        classNo = 'COSCO91'
                                        className = (CSIS.Lang.ID_140070||'油品');
                                    }

                                } else if (companyCode.startWith('65')&&selectRecord.invoiceSort == 'FY28') {
                                    url = 'fmm/vwFmmMtrPurchaseQuery.jsp';
                                    title = (CSIS.Lang.ID_237540||"关联信息(物料)");
                                }else if(selectRecord.invoiceSort == 'FYCL' || selectRecord.invoiceSort == 'FYHF'/*|| selectRecord.invoiceSort == 'FYHW' || selectRecord.invoiceSort == 'FYRG'*/){
                                    url = 'fmm/vwFmmBndPurchaseQuery.jsp';
                                    title = ("关联信息(绑垫料)");
                                }else if(selectRecord.invoiceSort == 'FY03'){
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_139630||"润料模块尚在建设，润料费还无法关联信息！");
                                    return ;
                                }else if(selectRecord.invoiceSort == 'FY70'){//航海资料 for test
                                    url = 'fmm/vwFmmVdmPurchaseQuery.jsp';
                                    title = ("关联信息(航海资料)");
                                }
                                else{
                                    Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_140080||"该费用类别无相关关联信息");
                                    return ;
                                }
                                //对于 66000000公司用户关联信息弹出框根据费用类别限制订货标示
                                if(companyCode.startWith("66")){
                                    var sortDetail = selectRecord.invoiceSortDetail
                                    if(sortDetail == 'FY63001' || sortDetail == 'FY04021' || sortDetail == 'FY65001' || sortDetail == 'FY56001'){
                                        //FY63001，订货标识限定为F 厂修备件 FY04021，订货标识限定为F 厂修物料；FY65001，订货标识限定为D 坞修油漆
                                        C.context.register('isDefaultOrderType',{sortDetail:sortDetail});
                                    }
                                }

                                var windowBox = new C.WindowBox({title:title,height:600,width:1200});
                                C.context.register('feeInvocieParm',{
                                    wBox:windowBox.getUI(),
                                    feeInvoiceId:selectRecord.feeInvoiceId,
                                    paymentNoticeId:selectRecord.paymentNoticeId,
                                    vesselCode:selectRecord.vesselCode,
                                    invoiceSort:selectRecord.invoiceSort,
                                    invoiceSortDetail:selectRecord.invoiceSortDetail,
                                    currency:selectRecord.currency,
                                    currencyName:selectRecord.currencyName,
                                    invoiceAmount:selectRecord.dtlAmount,
                                    invoiceAmountWithoutTax:selectRecord.dtlAmountWithoutTax,
                                    invoiceTax:selectRecord.dtlTaxAmount,
                                    invoiceStatus:selectRecord.invoiceStatus,
                                    vesselName:selectRecord.vesselName,
                                    taxRate:Number(selectRecord.taxRate),
                                    taxRateName:selectRecord.taxRateName,
                                    ifJigai:selectRecord.ifJigai,
                                    isFixedAsset:selectRecord.isFixedAsset,
                                    classNo:classNo,
                                    className:className,
                                    innerOrder:selectRecord.innerOrder,
                                    exchangeRate : selectRecord.exchangeRate,
                                    isAdvanceFee : selectRecord.isAdvanceFee
                                });
                                windowBox.addListener('closed',function(){
                                    changeGrid(currentRecord);
                                    var feeInvoiceBack = C.context.get('feeInvoiceBack');
                                    C.context.unRegister('feeInvoiceBack');
                                    if(feeInvoiceBack && feeInvoiceBack.saved){
                                        var rec = page.getGridBox().getSelectedStore();
                                        rec.set('projectName',CSIS.Lang.ID_140090||'已挂单');
                                        rec.commit();
                                    }
                                });
                                windowBox.loadPage(url);
                                C.currentWorkPage = windowBox.getUI();
                                windowBox.getUI().show();
                            }
                        }
                    }
            );


            var printBtn = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_105610||'打印',icon:'../res/img/themes/default/printer.png',
                handler:function(){
                    var selectRecord = page.getGridBox().getCheckedRecords();
                    if(selectRecord==null || selectRecord.length!==1){
                        Ext.MessageBox.alert(CSIS.Lang.ID_127050||"打印付款单",CSIS.Lang.ID_116090||"请选择并且每次只能打印一份付款单！");
                        return;
                    };
                    var record =  page.getGridBox().getSelectedRecord();
                    var printName = "";
                    //点击打印按钮时，将FMM_FEE_INVOICE表中付款单号和费用类别与当前记录付款单号和费用类别相同的记录，EXPORTID置为1，
                    var orderNo = record.orderNo
                    if(!orderNo){
                        Ext.MessageBox.alert(CSIS.Lang.ID_127050||"打印付款单","付款单号不存在，请先生成付款单后再打印！");
                        return;
                    }
                    C.ajax.callAction("updateExportId", 'feeInvoice', {orderNo: orderNo},
                            function(action,domainName,resp) {
                            });
                    //2018年12月8日20:06:21 yangxl 66000000用户都调用这个
                    if(!isEmpty(companyCode)&&companyCode=='66000000'){
                        rptName = "SP_FMM_PAYMENT_NOTICE_RPT_ZYHYSY.cpt";
                        url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&V_USER="+userCode+"&format=excel&__filename__=中远海运散运付款通知单";
                        C.rptpost(url);
                        return
                    }
                    if(!isEmpty(companyCode)&&youlunFlag){ //油运用后台手动的导出方法
                        //导出Excel
                        var excelProgress = new  CSIS.UploadWindow()
                        var excelName = (CSIS.Lang.ID_140100||"付款通知单") + dateFormat('',"_suffix") +".xls";
                        excelProgress.startDownload("feeInvoice",excelName,{paymentNoticeId:page.getGridBox().getSelectedRecord().paymentNoticeId,youlunPayment:'1'})
                    }else{
                        var url ="";
                        var rptName = "";
                        if(!isEmpty(record.payer)&&record.payer.substring(0,4)=='6619'){
                            // reportServerIP  = "10.18.7.64";
                            printName = (CSIS.Lang.ID_140110||'海南海盛航运有限公司实际发票确认单');   //excel打印的名字
                            rptName = "SP_FMM_PAYMENT_NOTICE_RPT_HS_NEW.cpt";
                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&V_USER="+userCode+"&format=excel&__filename__="+printName;
                        }else if(!isEmpty(record.payer)&&record.payer.substring(0,2)=='68'){
                            if(record.payer == '68920000')
                            {
                                printName = ('上海泛亚航运有限公司付款通知单');   //excel打印的名字
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_FYFK.cpt";
                            }
                            else
                            {
                                printName = (CSIS.Lang.ID_237220||'中远海运集装箱运输有限公司付款通知单');   //excel打印的名字
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_SYFK.cpt";
                            }
                            if(!record.paymentNoticeId){
                                Ext.MessageBox.alert(CSIS.Lang.ID_127050||"打印付款单",CSIS.Lang.ID_237550||"该发票未关联付款单ID！");
                                return;
                            }
                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NO="+record.orderNo+"&V_USER_NAME="+userCode+"&format=excel&__filename__="+printName;
                        }else if(!isEmpty(companyCode)&&(companyCode.substring(0,4)=='6601' || companyCode.substring(0,4)=='6603' || companyCode.substring(0,4)=='6604')){
                            if(!isEmpty(record.payer)&&record.payer=='66000000')   {
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_HYSH.cpt";
                                url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&format=excel";
                            }else if(!isEmpty(record.payer)&&record.payer=='66180000'){
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_ZSJTcpt.cpt";
                                url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&format=excel";
                            }else if(!isEmpty(record.payer)&& record.payer=="66070000")  {
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_CSTZ.cpt";
                                url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&format=excel";
                            }else if (!isEmpty(record.payer) && (record.payer == "71010000"||record.payer == "66047200")) {
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_SGP.cpt";
                                url = C.reportServerPath + "=report%2F" + rptName + "&V_PAYMENT_NOTICE_ID=" + record.paymentNoticeId + "&V_USER_NAME=" + userName + "&format=excel&__filename__=付款通知单";
                            }else{
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW.cpt";
                                url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&format=excel";
                            }
                        } else if(!isEmpty(record.payer)&&record.payer.substring(0,2) == "01") {
                            rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_ZYHF.cpt";
                            url = C.reportServerPath + "=report%2F" + rptName + "&V_PAYMENT_NOTICE_ID=" + record.paymentNoticeId + "&V_USER="+userCode +  "&format=excel&__filename__=付款通知单";
                        } else if(!isEmpty(record.payer) && record.payer.substring(0,2)=='63')  {
                            //厦远付款通知单
                            if(!isEmpty(record.invoiceSort) && record.invoiceSort=="FY19")
                            {
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_XYTDTZ.cpt";
                            }
                            else{
                                rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_XYTZ.cpt";
                            }
                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&format=excel&__filename__=付款通知单";
                        } else if (!isEmpty(record.payer) && (record.payer == "71010000"||record.payer == "66047200")) {
                            rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_SGP.cpt";
                            url = C.reportServerPath + "=report%2F" + rptName + "&V_PAYMENT_NOTICE_ID=" + record.paymentNoticeId + "&V_USER_NAME=" + userName + "&format=excel&__filename__=付款通知单";
                        } else if(!isEmpty(companyCode)&&companyCode=="68280000")  {
                            rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_SYFK.cpt";
                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NO="+record.orderNo+"&V_USER_NAME="+userCode+"&format=excel&__filename__=上远付款通知单";
                        }else if (!isEmpty(record.payer) && record.payer == "72000000") {
                            rptName = "SP_FMM_PAYMENT_NOTICE_RPT_FOR_NEW_UKFK.cpt";
                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NO="+record.orderNo+"&V_USER_NAME="+userCode+"&format=excel&__filename__=UK付款通知单";
                        }
                        else{
                            var rptName = "SP_FMM_PAYMENT_NOTICE_RPT.cpt";
                            if(!isEmpty(record.payer) && record.payer.substring(0,2)=='10'){
                                if(record.currency=="CNY"){
                                    rptName = "SP_FMM_PAYMENT_NOTICE_RPT_GUOTOU_CNY.cpt";
                                }else{
                                    rptName = "SP_FMM_PAYMENT_NOTICE_RPT_GUOTOU_USD.cpt";
                                }
                            }

                            url = C.reportServerPath + "=report%2F"+rptName+"&V_PAYMENT_NOTICE_ID="+record.paymentNoticeId+"&V_USER="+userCode+"&format=excel";
                        }
                        C.rptpost(url);
                    }
                }
            });

            var infoPrintBtn = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_105610||'打印',icon:'../res/img/themes/default/printer.png',
                handler:function(){
                    Ext.getElementById(printBtn.getId()).click()
                }
            });

            //和发票查询界面使用同样的导出，调用相同的后台 shizy20141109
            var excelBtn = Ext.create('Ext.button.Button', {
                text: CSIS.Lang.ID_108380||'导出',
                icon:'../res/img/themes/default/application_go.png',
                handler: function () {
                    var count = feeInvoiceDomain.getDataSource().getTotalCount();
                    if (count < 1){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_101550||"请先查询再导出！");
                        return;
                    }
                    if (count > 22000){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_237560||"每次导出不能超过2.2万条的记录！");
                        return;
                    }
                    searchParams.feeinvoiceFalg = true;
                    var storageProgress = new  CSIS.UploadWindow()
                    storageProgress.startDownload("feeinvoiceSearch",CSIS.Lang.ID_237570||"发票明细表.xls",searchParams);
                }
            });
            var feeInvoiceDomain;
            var page;
            if(youlunFlag){
                feeInvoiceDomain = feeInvoiceDomain2;
            }else if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='0200'){
                feeInvoiceDomain = feeInvoiceDomain4;
            }else if(companyCode.startsWith('08011100')){
                feeInvoiceDomain = feeInvoiceDomain1
            }else{
                feeInvoiceDomain = feeInvoiceDomain1;
            }
            page = new CSIS.WorkPageBox(feeInvoiceDomain, {
                    search: true,
                    searchBoxConfig:{
                        columns:CSIS.lang=="EN"?4:6,
                        showMultiVessel:true,
                        labelWidth:CSIS.lang=="EN"?150:100,
                    },
                    editBoxConfig:{
                        height:'100%',
                        labelWidth:105
                    },
                    helpPage:"fmm/FMM_USER_MANUAL.htm",
                    showEditorBoxFirst: true,
                    gridBoxConfig:{
                        showCheckBox:true,
                        lineRender:function(record) {
                            if(record.data.amount < 0)   return 'CSIS-LINE-RED';
                            if(record.data.isDoubt == "1" && !youlunFlag)   return 'CSIS-LINE-RED';
                        }
                    },
                    toolbarBoxConfig:{
                        useSimpleSearch:false,
                        extendsButtons:[
                        ]
                    }
                }
            );
            page.getGridBox().getUI().columns[0].width = 35;
            //油运加个清空录入按钮
            if(!isEmpty(companyCode)&&youlunFlag){
                var clearGridButton = Ext.create('Ext.button.Button',{text: CSIS.Lang.ID_140120||'清空录入',icon:'../res/img/themes/default/table_delete.png',
                    handler: function () {
                        var checkRecord = page.getGridBox().getCheckedStore();
                        if(checkRecord.length <= 0 ){
                            Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_140130||'请选中需要清空的行！');
                            return;
                        }
                        //删除前先保存原来数据，之后相减
                        var subAmountTotal = 0;
                        var subAmountWithoutTax = 0;
                        Ext.each(checkRecord,function(v){
                            subAmountTotal = accAdd(subAmountTotal, v.data.baseAmount);
                            subAmountWithoutTax = accAdd(subAmountWithoutTax, v.data.baseAmountWithoutTax);
                        });
                        feeInvoiceDomain.getDataSource().deleteRecords( page.getGridBox().getCheckedStore());
                        var baseAmountTotal  = Ext.getCmp(baseAmountTotalId).getValue();
                        var baseAmountWithoutTax  = Ext.getCmp(baseAmountWithoutTaxId).getValue();
                        Ext.getCmp(baseAmountTotalId).setValue(subtract(baseAmountTotal,subAmountTotal));
                        Ext.getCmp(baseAmountWithoutTaxId).setValue(subtract(baseAmountWithoutTax,subAmountWithoutTax));
                    }
                })
                page.getGridBox().addToPagingBar(clearGridButton)
            }

            page.getEditBox().getExtField("vesselCode").addListener('change',function(src,n){
                var invoiceSortDetail = page.getEditBox().getExtField("invoiceSortDetail").getValue();
                var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                var foreStatMonth = page.getEditBox().getExtField("foreStatMonth").getValue();
                var innerNo = getJgInnerOrderNoByInDetail(invoiceSortDetail,vesselCode,foreStatMonth);
                getVovayeInfo()
                if(!isEmpty(innerNo)){
                    page.getEditBox().getExtField('billNo').setValue(innerNo);
                }
            });
            page.getEditBox().getExtField("occurTimeFrom").addListener('change',function(src,n){
                getVovayeInfo()
            })
            if (bndFlag) {
                page.getEditBox().getExtField("voyageNo").addListener('change',function(src,n){
                    var voyageNo = page.getEditBox().getExtField("voyageNo").getValue();
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                    if (voyageNo && vesselCode) {
                        C.syncRequest.callAction('list', 'vwVopVesselOfficers', {
                            _extend: " and vesselShoreInd = 'D' and vesselCode = '"+vesselCode+"' and role = '"+voyageNo+"' "
                        }, function (actionName, domainName, resp) {
                            if (resp && resp.rows && resp.rows.length>0) {
                                page.getEditBox().getExtField("director").setComboValue(resp.rows[0].manager,resp.rows[0].managerName);
                                tempFields.put('usrName',resp.rows[0].managerName)
                            }
                        });
                    }
                })
            }
            //所属公司是02000000
            if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='0200'){
                var baseAmountWithoutTaxId = Ext.id();
                var baseAmountTotalId = Ext.id();
                var baseAmountBillQuoteId = Ext.id();
                var baseAmountCheckAmountId = Ext.id();
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountCheckAmountId,
                    name:'baseAmountCheckAmountTotal',
                    fieldLabel:CSIS.Lang.ID_139380||'核定金额',
                    labelAlign : 'right',
                    readOnly:true,
                    labelWidth:75,
                    width: 150
                })
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountBillQuoteId,
                    name:'baseAmountBillQuoteTotal',
                    fieldLabel:CSIS.Lang.ID_124450||'账单报价',
                    labelAlign : 'right',
                    readOnly:true,
                    labelWidth:75,
                    width: 150
                })
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountWithoutTaxId,
                    name:'baseAmountWithoutTaxTotal',
                    fieldLabel:CSIS.Lang.ID_140140||'人民币不含税总额',
                    labelAlign : 'right',
                    readOnly:true,
                    labelWidth:75,
                    width: 150
                })
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountTotalId,
                    name:'baseAmountTotal',
                    fieldLabel:CSIS.Lang.ID_140150||'人民币总额',
                    labelAlign : 'right',
                    readOnly:true,
                    labelWidth:75,
                    width: 180
                })
            }else{
                var baseAmountWithoutTaxId = Ext.id();
                var baseAmountTotalId = Ext.id();
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountWithoutTaxId,
                    name:'baseAmountWithoutTaxTotal',
                    fieldLabel:CSIS.Lang.ID_140140||'人民币不含税总额',
                    labelAlign : 'right',
                    readOnly:true,
                })
                page.getGridBox().addToPagingBar({
                    xtype:'textfield',
                    id:baseAmountTotalId,
                    name:'baseAmountTotal',
                    fieldLabel:CSIS.Lang.ID_140150||'人民币总额',
                    labelAlign : 'right',
                    readOnly:true,
                })
            }
            /**保存关联信息tab页的内容
             */
            var doSaveFmmOpeRelevance = function(){
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                if(invoiceSort == 'FY01'||invoiceSort == 'FY02' ||invoiceSort == 'FY62'||invoiceSort== 'FY63' ||invoiceSort == 'FY64'||invoiceSort == 'FY67'||invoiceSort == 'FY61'||invoiceSort == 'FY97'){
                    if(invoiceSortDetail == 'FY01003'||invoiceSortDetail == 'FY01004'||
                            invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004' ||invoiceSort== 'FY63'){//备件订购
                        doSaveBJ()
                    }else if(invoiceSortDetail == 'FY01002' || invoiceSortDetail == 'FY01005'
                            || invoiceSortDetail == 'FY01007'|| invoiceSort == 'FY62'|| invoiceSort == 'FY67' || invoiceSort == 'FY97'){//航修通导订购
                        doSaveTD()
                    }else{
                        //修理模块尚在建设
                    }
                }else if(invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66' || invoiceSort == 'FY58'){//物料订购
                    doSaveWL()
                }else if(invoiceSort == 'FY03'){
                    //润料模块尚在建设
                }
            }

            //add on 210527
            function addHHZLOrder(){
                C.syncRequest.callAction('list','orderSeachartVo',{_extend:" and orderNumber = '"+enquireNo +"'"} ,function(action, domainName, resp){
                    var orderType = resp.rows[0].orderType
                    if(orderType=='0'||orderType=='1'){
                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY70","船舶资料费")
                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY70001","电子海图及图书费用")//resp.rows[0].applyBusiType,resp.rows[0].applyBusiTypeName
                    }else{
                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY70","船舶资料费")
                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY70002","纸质海图及图书费用")//resp.rows[0].applyBusiType,resp.rows[0].applyBusiTypeName
                    }

                    page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName);
                    page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].orderNumber)
                    page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].payee,resp.rows[0].payeeName)
                    tempFields.put('vesselName', resp.rows[0].vesselName);
                    tempFields.put('payeeName', resp.rows[0].payeeName);

                    //付款单位
                    C.syncRequest.callAction('callSpManagement','feeInvoice',{vesselCode:resp.rows[0].vesselCode,date:new Date(),manageType:'6',currentCompany:'<%=user.getCompanyCode()%>'},
                            function(action,domainName,resp){
                                if(resp && resp.rows && resp.rows.length>0){
                                    page.getEditBox().getExtField('payer').setComboValue(resp.rows[0].MANAGEMENT_CODE,resp.rows[0].MANAGEMENT_NAME);
                                    tempFields.put('customerName', resp.rows[0].MANAGEMENT_NAME);
                                }
                            });

                    if(resp.rows[0].currency!='CNY'){
                        page.getEditBox().setValue('ifCanUseTax',"0");   //是否增值税
                        page.getEditBox().setValue("taxRate","0")
                    }

                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                            function(action,domainName,resp){
                                page.getEditBox().setValue('exchangeRate',resp);
                            });
                    page.getEditBox().setValue("innerOrder",resp.rows[0].orderNumber)
                    page.getEditBox().getExtField("currency").setComboValue(resp.rows[0].currency, resp.rows[0].currencyName)

                    var totalFee = isEmpty(resp.rows[0].totalFee)?0:Number(resp.rows[0].totalFee)
                    page.getEditBox().setValue("dtlAmount",totalFee)//含税金额(元)
                    page.getEditBox().setValue("amount",totalFee)//发票总金额(元)
                    if(isEmpty(resp.rows[0].totalFeeCny)){
                        var exchangeRate = page.getEditBox().getExtField("exchangeRate").getValue()
                        var wlBaseAmount = totalFee * exchangeRate
                        page.getEditBox().setValue("baseAmount",wlBaseAmount)
                    }else{
                        page.getEditBox().setValue("baseAmount",resp.rows[0].totalFeeCny)//人民币金额（元）
                    }
                    var taxRate = Number(page.getEditBox().getValue('taxRate'));//税率
                    var dtlTaxAmount = accMul((accDiv(totalFee,(1+taxRate))),taxRate).toFixed(2);//计算不含税金额
                    var dtlAmountWithoutTax = taxRate==0?totalFee:totalFee - dtlTaxAmount
                    page.getEditBox().setValue("dtlAmountWithoutTax",dtlAmountWithoutTax)//不含税金额(元)
                    page.getEditBox().setValue("amountWithoutTax",dtlAmountWithoutTax)//不含税总金额(元)
                    page.getEditBox().getExtField("vesselDept").setComboValue(resp.rows[0].dept,resp.rows[0].deptName);
                    tempFields.put('vesselName', resp.rows[0].vesselName);
                    tempFields.put('payeeName', resp.rows[0].payeeName);
                    tempFields.put('currencyName', resp.rows[0].currencyName);

                    page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].applyDate)
                    //入账年度与当前时间相同
                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());

                    C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                        if(resp&&resp.rows&&resp.rows.length>0){
                            var rs = resp.rows[0]
                            var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                            var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                            var director =  getDirector(selectFreightType,companyCode,vesselCode);
                            if(!isEmpty(director)){
                                page.getEditBox().getExtField("director").setValue(director);
                            }else{
                                page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                            }
                            tempFields.put('usrName', rs.engineManagerName);
                            page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                            tempFields.put('departmentName', rs.manageDeptName);
                        }
                    });

                    //费用流向的逻辑
                    C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].payee},function(a,b,resp){
                        if(resp&&resp.rows&&resp.rows.length>0){
                            var rs = resp.rows[0]
                            page.getEditBox().getExtField('feeFlow').setComboValue(rs.chargeFlow,rs.chargeFlow);
                        }
                    })

                })

            }

            function addBjOrder(){
                //foreStatMonth,invoiceSort,invoiceSortDetail  currency
                C.syncRequest.callAction('listFeeOrder','enquireMainVo',{_extend:" and enquireNo = '"+enquireNo +"'"} ,
                        function (action, domainName, resp){
                            var manager="";
                            C.syncRequest.callAction('getVesselManager', 'applyMainMtrVo',{vesselCode:resp.rows[0].vesselCode}, function (actionName, domainName, resp) {
                                manager=resp.msg;
                            });
                            var orderType = resp.rows[0].orderType
                            if(enquireType=='BJ'){
                                if(manager.startWith('6601')&&isBjOrderCreate){
                                    if(orderType=='I'){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY64", "设备更新和技术改造费")
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY64002","技术改造费")
                                    }else if(orderType=='G'){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY64", "设备更新和技术改造费")
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY64001","设备更新费")
                                    }else if(orderType=='F'){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY63", CSIS.Lang.ID_126950 || "备件费")
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63001","厂修备件费")
                                    }else if(orderType=='E'){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("", "")
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","")
                                    }else{
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY63", CSIS.Lang.ID_126950 || "备件费")
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63002", CSIS.Lang.ID_139510 || "日常备件费")
                                    }
                                }else {
                                    page.getEditBox().getExtField("invoiceSort").setComboValue("FY63", CSIS.Lang.ID_126950 || "备件费")
                                    if (companyCode.substring(0, 2) != '01') {
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63002", CSIS.Lang.ID_139510 || "日常备件费")
                                    }
                                }
                            }else if(enquireType=='WL'){
                                page.getEditBox().getExtField("invoiceSort").setComboValue("FY04",CSIS.Lang.ID_140160||"物料费")
                                page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY04022",CSIS.Lang.ID_139520||"日常维修保养物料费")//resp.rows[0].applyBusiType,resp.rows[0].applyBusiTypeName
                            }
                            //备件订购界面跳转确定集团费用大类与科目
                            if(enquireType=='BJ'){
                                setGroupSortAndDetailByInvoiceSortDetail("FY63002")
                            }else if(enquireType=='WL'){
                                setGroupSortAndDetailByInvoiceSortDetail("FY04022")
                            }
                            doCreateFmmOpeRelevance(resp.rows[0])//给关联信息tab页赋值
                            // YANGXL 2018-08-20 初始赋值付款状态的签收单号、经办人
                            C.syncRequest.callAction("searchSignNo", "enquireMainVo", {vesselCode:resp.rows[0].vesselCode,applyNo:resp.rows[0].applyNo}, function (actionName, domainName, resp) {
                                if(resp.success){
                                    page.getEditBox().setValue('signNo',resp.msg);
                                }
                            });
                            C.syncRequest.callAction("searchConfirmUser", "enquireMainVo", {enquireMainId:resp.rows[0].enquireMainId}, function (actionName, domainName, resp) {
                                if(resp.success){
                                    page.getEditBox().setValue('confirmUser',resp.msg);
                                }
                            });

                            if(resp.rows[0].currency!='CNY'){
                                page.getEditBox().setValue('ifCanUseTax',"0");   //是否增值税
                                page.getEditBox().setValue("taxRate","0")
                            }
                            C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                    function(action,domainName,resp){
                                        page.getEditBox().setValue('exchangeRate',resp);
                                    });
                            page.getEditBox().setValue("innerOrder",resp.rows[0].enquireNo)
                            page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode,resp.rows[0].vesselName)
                            if(isBjOrderCreate) {
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].supplierCode, resp.rows[0].supplierName)
                                page.getEditBox().getExtField("currency").setComboValue(resp.rows[0].currency,resp.rows[0].currencyName)
                            }
                            //非6601公司备件跳转发票录入再赋值金额
                            if(!tianjinFlagTwo){
                                var totalFee = isEmpty(resp.rows[0].totalFee)?0:Number(resp.rows[0].totalFee)
                                page.getEditBox().setValue("dtlAmount",totalFee)//含税金额(元)
                                page.getEditBox().setValue("amount",totalFee)//发票总金额(元)
                                if(isEmpty(resp.rows[0].totalFeeCny)){
                                    var exchangeRate = page.getEditBox().getExtField("exchangeRate").getValue()
                                    var wlBaseAmount = totalFee * exchangeRate
                                    page.getEditBox().setValue("baseAmount",wlBaseAmount)
                                }else{
                                    page.getEditBox().setValue("baseAmount",resp.rows[0].totalFeeCny)//人民币金额（元）
                                }
                                var taxRate = Number(page.getEditBox().getValue('taxRate'));//税率
                                var dtlTaxAmount = accMul((accDiv(totalFee,(1+taxRate))),taxRate).toFixed(2);//计算不含税金额
                                var dtlAmountWithoutTax = taxRate==0?totalFee:totalFee - dtlTaxAmount
                                page.getEditBox().setValue("dtlAmountWithoutTax",dtlAmountWithoutTax)//不含税金额(元)
                                page.getEditBox().setValue("amountWithoutTax",dtlAmountWithoutTax)//不含税总金额(元)
                            }
                            page.getEditBox().getExtField("vesselDept").setComboValue(resp.rows[0].dept,resp.rows[0].deptName);
                            tempFields.put('vesselName', resp.rows[0].vesselName);
                            tempFields.put('payeeName', resp.rows[0].supplierName);
                            tempFields.put('currencyName', resp.rows[0].currencyName);
                            //付款单位
                            setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                            var payer = page.getEditBox().getExtField('payer').getValue()
                            //获取船管主体(针对天津公司6601订购日期作为入账年度,物料的完工日期优先取订购日期)
                            var invoiceSort = page.getEditBox().getExtField("invoiceSort").getValue();
                            //备件-选中订单号的订购日期是2017年签收日期是2018年的默认完工日期为2017-12-31入账年度2017
                            var bl = !isEmpty(resp.rows[0].orderDate) && !isEmpty(resp.rows[0].applyDate) && (Number(new Date(resp.rows[0].orderDate).getFullYear())==2017) && (Number(new Date(resp.rows[0].applyDate).getFullYear())==2018)?true:false;
                            //完工日期invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66'
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66')){
                                if(resp.rows[0].orderDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].orderDate)
                            }else if(invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0,4) && !("66010000" == payer)){
                                page.getEditBox().getExtField('occurTimeFrom').setValue(new Date('2017-12-31'))
                                page.getEditBox().getExtField('occurTimeTo').setValue(resp.rows[0].applyDate);
                            }else if (manager.startWith('68')&&resp.rows[0].sendVesselDate) {
                                page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].sendVesselDate)
                            }else{
                                if(resp.rows[0].applyDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].applyDate)
                            }
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66')){
                                if(resp.rows[0].orderDate){
                                    //入账年度与订购时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].orderDate));
                                }else{
                                    //入账年度与当前时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }else{
                                if(invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0,4) && !("66010000" == payer)){
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date('2017-12-31'));
                                }else if (manager.startWith('68')&&resp.rows[0].sendVesselDate) {
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].sendVesselDate));
                                }else if(resp.rows[0].applyDate){
                                    //入账年度与完工时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].applyDate));
                                }else if(resp.rows[0].orderDate){
                                    //入账年度与订购时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].orderDate));
                                }else{
                                    //入账年度与当前时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }
                            C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                    var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                    if(!isEmpty(director)){
                                        page.getEditBox().getExtField("director").setValue(director);
                                    }else{
                                        page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                    }
                                    tempFields.put('usrName', rs.engineManagerName);
                                    page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                    tempFields.put('departmentName', rs.manageDeptName);
                                }
                            });
                            //费用流向的逻辑
                            C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].supplierCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    page.getEditBox().getExtField('feeFlow').setComboValue(rs.chargeFlow,rs.chargeFlow);
                                }
                            })
                        });

            }
            function addWLOrder(){
                C.syncRequest.callAction('listFeeOrder','enquireMainMtrVo',{_extend:" and enquireNo = '"+enquireNo +"'"} ,
                        function (action, domainName, resp){
                            if(enquireType=='BJ'){
                                page.getEditBox().getExtField("invoiceSort").setComboValue("FY63",CSIS.Lang.ID_126950||"备件费")
                                page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY63002",CSIS.Lang.ID_139510||"日常备件费")
                            }else if(enquireType=='WL'){
                                page.getEditBox().getExtField("invoiceSort").setComboValue("FY04",CSIS.Lang.ID_140160||"物料费")
                                page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY04022",CSIS.Lang.ID_139520||"日常维修保养物料费")//resp.rows[0].applyBusiType,resp.rows[0].applyBusiTypeName,
                            }
                            //物料订购界面跳转确定集团费用大类与科目
                            if(enquireType=='BJ'){
                                setGroupSortAndDetailByInvoiceSortDetail("FY63002")
                            }else if(enquireType=='WL'){
                                setGroupSortAndDetailByInvoiceSortDetail("FY04022")
                            }
                            doCreateFmmOpeRelevance(resp.rows[0])//给关联信息tab页赋值
                            C.syncRequest.callAction("searchSignNo", "enquireMainMtrVo", {vesselCode:resp.rows[0].vesselCode,applyNo:resp.rows[0].applyNo}, function (actionName, domainName, resp) {
                                if(resp.success){
                                    page.getEditBox().setValue('signNo',resp.msg);
                                }
                            });
                            if(!isEmpty(resp.rows[0].operatorName)){
                                page.getEditBox().setValue('confirmUser',resp.rows[0].operatorName);
                            }

                            //前提增值税赋值，避免金额重新计算
                            if(resp.rows[0].currency!='CNY'){
                                page.getEditBox().setValue('ifCanUseTax',"0");   //是否增值税
                                page.getEditBox().setValue("taxRate","0")
                            }
                            //配合重新计算人民币金额前提exchangeRate
                            C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                    function(action,domainName,resp){
                                        page.getEditBox().setValue('exchangeRate',resp);
                                    });
                            page.getEditBox().setValue("innerOrder",resp.rows[0].enquireNo)
                            page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode,resp.rows[0].vesselName)
                            page.getEditBox().getExtField("currency").setComboValue(resp.rows[0].currency,resp.rows[0].currencyName)
                            page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].supplierCode,resp.rows[0].supplierName)
                            var standardPriceAmount = 0
                            C.syncRequest.callAction('getStandardPrice', 'enquireDetailMtr', {id: resp.rows[0].enquireMainMtrId},
                                    function (action, domainName,resp) {
                                        standardPriceAmount = Number(resp.msg)
                                    }
                            );
                            //非6601公司备件跳转发票录入再赋值金额
                            if(!tianjinFlagTwo){
                                var totalFee = isEmpty(resp.rows[0].totalFee)?0:Number(resp.rows[0].totalFee)
                                page.getEditBox().setValue("dtlAmountWithoutTax",standardPriceAmount)
                                page.getEditBox().setValue("amountWithoutTax",standardPriceAmount)
                                page.getEditBox().setValue("dtlAmount",totalFee)
                                page.getEditBox().setValue("amount",totalFee)
                                if(isEmpty(resp.rows[0].totalFeeCny)){
                                    var exchangeRate = page.getEditBox().getExtField("exchangeRate").getValue()
                                    var wlBaseAmount = totalFee * exchangeRate
                                    page.getEditBox().setValue("baseAmount",wlBaseAmount)//baseAmount,人民币金额（元）
                                }else{
                                    page.getEditBox().setValue("baseAmount",resp.rows[0].totalFeeCny)//baseAmount,人民币金额（元）
                                }
                                var taxRate = Number(page.getEditBox().getValue('taxRate'));//税率
                                var dtlTaxAmount = accMul((accDiv(totalFee,(1+taxRate))),taxRate).toFixed(2);//计算不含税金额
                                var dtlAmountWithoutTax = taxRate==0?totalFee:totalFee - dtlTaxAmount
                                page.getEditBox().setValue("dtlAmountWithoutTax",dtlAmountWithoutTax)
                                page.getEditBox().setValue("amountWithoutTax",dtlAmountWithoutTax)
                            }
                            page.getEditBox().getExtField("vesselDept").setComboValue(resp.rows[0].dept,resp.rows[0].deptName);
                            tempFields.put('vesselName', resp.rows[0].vesselName);
                            tempFields.put('payeeName', resp.rows[0].supplierName);
                            tempFields.put('currencyName', resp.rows[0].currencyName);
                            //付款单位
                            setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                            var payer = page.getEditBox().getExtField('payer').getValue()
                            //获取船管主体(针对天津公司6601订购日期作为入账年度,物料的完工日期优先取订购日期)
                            var invoiceSort = page.getEditBox().getExtField("invoiceSort").getValue()
                            var manager=""
                            C.syncRequest.callAction('getVesselManager', 'applyMainMtrVo',{vesselCode:resp.rows[0].vesselCode}, function (actionName, domainName, resp) {
                                manager=resp.msg;
                            });
                            if(isWlOrderCreate){
                                if(("6603" == manager.toString().substring(0,4)||'66000000'==payer||'66180000'==payer||'66190000'==payer) && applyBusiType=='M'){
                                    page.getEditBox().getExtField('ifJigai').setValue('1');
                                }
                                page.getEditBox().getExtField("taxRate").setDisabled(false);

                            }
                            //备件-选中订单号的订购日期是2017年签收日期是2018年的默认完工日期为2017-12-31入账年度2017
                            var bl = !isEmpty(resp.rows[0].orderDate) && !isEmpty(resp.rows[0].applyDate) && (Number(new Date(resp.rows[0].orderDate).getFullYear())==2017) && (Number(new Date(resp.rows[0].applyDate).getFullYear())==2018)?true:false;
                            //完工日期invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66'
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66')){
                                if(resp.rows[0].orderDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].orderDate)
                            }else if(invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0,4) && !("66010000" == payer)){
                                page.getEditBox().getExtField('occurTimeFrom').setValue(new Date('2017-12-31'))
                                page.getEditBox().getExtField('occurTimeTo').setValue(resp.rows[0].applyDate);
                            }else if (manager.startWith('68')&&resp.rows[0].sendVesselDate) {
                                page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].sendVesselDate)
                            }else{
                                if(resp.rows[0].applyDate)
                                    page.getEditBox().getExtField('occurTimeFrom').setValue(resp.rows[0].applyDate)
                            }
                            if("6601" == manager.toString().substring(0,4) && (invoiceSort == 'FY04' || invoiceSort== 'FY33'|| invoiceSort== 'FY65'|| invoiceSort == 'FY66')){
                                if(resp.rows[0].orderDate){
                                    //入账年度与订购时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].orderDate));
                                }else{
                                    //入账年度与当前时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }else{
                                if(invoiceSort == "FY63" && bl && "6601" == manager.toString().substring(0,4) && !("66010000" == payer)){
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date('2017-12-31'));
                                }else if (manager.startWith('68')&&resp.rows[0].sendVesselDate) {
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].sendVesselDate));
                                }else if(resp.rows[0].applyDate){
                                    //入账年度与完工时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].applyDate));
                                }else if(resp.rows[0].orderDate){
                                    //入账年度与订购时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date(resp.rows[0].orderDate));
                                }else{
                                    //入账年度与当前时间相同
                                    page.getEditBox().getExtField('foreStatMonth').setValue(new Date());
                                }
                            }
                            C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                    var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                    if(!isEmpty(director)){
                                        page.getEditBox().getExtField("director").setValue(director);
                                    }else{
                                        page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                    }
                                    tempFields.put('usrName', rs.engineManagerName);
                                    page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                    tempFields.put('departmentName', rs.manageDeptName);
                                }
                            });
                            //费用流向的逻辑
                            C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].supplierCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    page.getEditBox().getExtField('feeFlow').setComboValue(rs.chargeFlow,rs.chargeFlow);
                                }
                            })
                        });
                if(companyCode.startWith("01")){
                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","")
                }

            }

            function WGaddBjOrder(){
                //费用类别、费用科目
                C.syncRequest.callAction('list','completionReportVo',{_extend:" and completionReportId= '"+completionReportId +"'"} ,
                        function (action, domainName, resp){
                            if(resp.total>0) {
                                page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName)
                                page.getEditBox().getExtField("billNo").setValue(resp.rows[0].innerOrder)
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].repairFactory,resp.rows[0].repairFactoryName)
                                page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].compDate)
                                page.getEditBox().getExtField("billNo").setComboValue(resp.rows[0].innerOrder,resp.rows[0].innerOrder)
                                if(cusType == 'JS'){
                                    page.getEditBox().getExtField("innerOrder").setValue(enquireNo)
                                }else{
                                    page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].projectNo)
                                }

                                //是否安全生产费用
                                page.getEditBox().getExtField("safeFlag").setValue(resp.rows[0].isSafeprod)
                                var vesselManagement=  getManagementByVesselCode(resp.rows[0].vesselCode);
                                Ext.defer(function(){
                                    page.getEditBox().getExtField("billNo").setComboValue(resp.rows[0].innerOrder,resp.rows[0].innerOrder)
                                },1000);
                                page.getEditBox().getExtField("billNo").setComboValue(resp.rows[0].innerOrder,resp.rows[0].innerOrder)                                //费用类别和费用小类业务逻辑

                                //费用类别和费用小类业务逻辑
                                var codeValueStr = "'"+vesselManagement+"','00000000'";
                                var vess_sort_codeValue="";
                                var vess_sort_display="";
                                var jt_sort_codeValue="";
                                var jt_sort_display="";
                                if(companyCode && companyCode.substring(0,2)!='63'){
                                    C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_SORT",codeValue:resp.rows[0].repairType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp1){
                                        if(resp1&&resp1.rows.length>0){
                                            Ext.each(resp1.rows,function(v){
                                                if(v.displayValueExtraEn==vesselManagement){
                                                    vess_sort_codeValue = v.codeValue;
                                                    vess_sort_display = v.displayValueCn;
                                                }
                                                if(v.displayValueExtraEn=="00000000"){
                                                    jt_sort_codeValue = v.codeValue;
                                                    jt_sort_display = v.displayValueCn;
                                                }
                                            })
                                        }
                                    })
                                    if(!isEmpty(vess_sort_codeValue)){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue(vess_sort_codeValue,vess_sort_display);
                                    }else{
                                        page.getEditBox().getExtField("invoiceSort").setComboValue(jt_sort_codeValue,jt_sort_display);
                                    }
                                }

                                var vess_detail_codeValue="";
                                var vess_detail_display="";
                                var jt_detail_codeValue="";
                                var jt_detail_display="";
                                if(companyCode && companyCode.substring(0,2)!='63'){
                                    C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_COURSE",codeValue:resp.rows[0].repairSmallType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp3){
                                        if(resp3&&resp3.rows.length>0){
                                            Ext.each(resp3.rows,function(v){
                                                if(v.displayValueExtraEn==vesselManagement){
                                                    vess_detail_codeValue = v.codeValue;
                                                    vess_detail_display = v.displayValueCn;
                                                }
                                                if(v.displayValueExtraEn=="00000000"){
                                                    jt_detail_codeValue = v.codeValue;
                                                    jt_detail_display = v.displayValueCn;
                                                }
                                            })
                                        }
                                    })
                                    if(!isEmpty(vess_detail_codeValue)){
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue(vess_detail_codeValue,vess_detail_display);
                                    }else{
                                        page.getEditBox().getExtField("invoiceSortDetail").setComboValue(jt_detail_codeValue,jt_detail_display);
                                    }
                                }

                                var invoiceSortDetailVal=page.getEditBox().getExtField("invoiceSortDetail").getComboValue();
                                if(invoiceSortDetailVal&&invoiceSortDetailVal.display.startWith('FY')){
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","");
                                }


                                //时代航运公司，厂修费增加默认
                                if(companyCode && companyCode.startWith("080111")){
                                    if(resp.rows[0].repairType=="WX" || resp.rows[0].repairType=="CX"){
                                        page.getEditBox().getExtField("invoiceSort").setComboValue("FY49","计修费");
                                    }
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","");
                                }

                                //审计文号
                                page.getEditBox().getExtField("auditNo").setValue(resp.rows[0].audit_no);

                                //币种
                                page.getEditBox().getExtField('currency').setComboValue(resp.rows[0].currency,resp.rows[0].currencyName);
                                tempFields.put('currencyName', resp.rows[0].currencyName);
                                //汇率
                                C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            page.getEditBox().setValue('exchangeRate',resp);
                                        });
                                //是否增值税
                                if(resp.rows[0].currency == 'CNY')
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()
                                //不含税金额
                                if(resp.rows[0].dtlAmountWithoutTax){
                                    page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(resp.rows[0].dtlAmountWithoutTax);
                                    page.getEditBox().getExtField('amountWithoutTax').setValue(resp.rows[0].dtlAmountWithoutTax);
                                }
                                //税率
                                if(resp.rows[0].taxRate||resp.rows[0].taxRate==0)
                                    page.getEditBox().setValue("taxRate",resp.rows[0].taxRate.toString());

                                //税额
                                if(resp.rows[0].dtlTaxAmount||resp.rows[0].dtlTaxAmount==0){
                                    page.getEditBox().getExtField('dtlTaxAmount').setValue(resp.rows[0].dtlTaxAmount);
                                    page.getEditBox().getExtField('taxAmount').setValue(resp.rows[0].dtlTaxAmount);
                                }
                                //含税金额
                                if(resp.rows[0].finishedCost){
                                    page.getEditBox().getExtField('dtlAmount').setValue(resp.rows[0].finishedCost);
                                    page.getEditBox().getExtField('amount').setValue(resp.rows[0].finishedCost);
                                }
                                //人民币金额
                                if(resp.rows[0].planActualCost)
                                    page.getEditBox().getExtField('baseAmount').setValue(resp.rows[0].planActualCost);

                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })
                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                                C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                        var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                        tempFields.put('usrName', rs.engineManagerName);
                                        page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                        tempFields.put('departmentName', rs.manageDeptName);
                                    }
                                });
                            }else{
                                Ext.MessageBox.alert(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_140170||"失败！请检查是否选择完工单！")
                            }
                        })
            }

            function TDaddBjOrder(){
                C.syncRequest.callAction('list','vrmWorkorder',{_extend:" and workorderId= '"+completionReportId +"'"} ,
                        function(action, domainName, resp){
                            if(resp.total>0) {
                                var vesselManagement=  getManagementByVesselCode(resp.rows[0].vesselCode);
                                //根据查询的通导工单数据绑定发票录入的默认值
                                page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName);
                                page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].workorderNo)
                                page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].workDate)
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].vendor,resp.rows[0].vendorName)
                                tempFields.put('vesselName', resp.rows[0].vesselName);
                                tempFields.put('payeeName', resp.rows[0].vendorName);
                                if(!isEmpty(resp.rows[0].workDate)){
                                    var fullYear = new Date(resp.rows[0].workDate).getFullYear();
                                    page.getEditBox().getExtField("foreStatMonth").setValue(fullYear);
                                }
                                //费用类别和费用小类业务逻辑
                                var codeValueStr = "'"+vesselManagement+"','00000000'";
                                var vessel_sort_codeValue="";
                                var vessel_sort_display="";
                                var jt_sort_codeValue="";
                                var jt_sort_display="";

                                C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_SORT",codeValue:resp.rows[0].workorderType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp){
                                    if(resp&&resp.rows.length>0){
                                        Ext.each(resp.rows,function(v){
                                            if(v.displayValueExtraEn==vesselManagement){
                                                vessel_sort_codeValue = v.codeValue;
                                                vessel_sort_display = v.displayValueCn;
                                            }
                                            if(v.displayValueExtraEn=="00000000"){
                                                jt_sort_codeValue = v.codeValue;
                                                jt_sort_display = v.displayValueCn;
                                            }
                                        })
                                    }
                                });

                                var vessel_detail_codeValue="";
                                var vessel_detail_display="";
                                var jt_detail_codeValue="";
                                var jt_detail_display="";
                                C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_COURSE",codeValue:resp.rows[0].workReason,displayValueExtraEn:codeValueStr},function(actionName, domainName, resp){
                                    if(resp&&resp.rows.length>0){
                                        Ext.each(resp.rows,function(v){
                                            if(v.displayValueExtraEn==vesselManagement){
                                                vessel_detail_codeValue = v.codeValue;
                                                vessel_detail_display = v.displayValueCn;
                                            }
                                            if(v.displayValueExtraEn=="00000000"){
                                                jt_detail_codeValue = v.codeValue;
                                                jt_detail_display = v.displayValueCn;
                                            }
                                        })
                                    }
                                })

                                //存在自定义的就使用自定义,    默认集团的
                                if(!isEmpty(vessel_sort_codeValue)){ //费用类别
                                    page.getEditBox().getExtField("invoiceSort").setComboValue(vessel_sort_codeValue,vessel_sort_display);
                                    tempFields.put('freightTypeName',vessel_sort_display);
                                }else{
                                    page.getEditBox().getExtField("invoiceSort").setComboValue(jt_sort_codeValue,jt_sort_display);
                                    tempFields.put('freightTypeName',jt_sort_display);
                                }

                                if(!isEmpty(vessel_detail_codeValue)){ //费用科目
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue(vessel_detail_codeValue,vessel_detail_display);
                                    tempFields.put('freightName',vessel_detail_display);
                                }else{
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue(jt_detail_codeValue,jt_detail_display);
                                    tempFields.put('freightName',jt_detail_display);
                                }

                                //船
                                C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                        var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                        tempFields.put('usrName', rs.engineManagerName);
                                        page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                        tempFields.put('departmentName', rs.manageDeptName);
                                    }
                                });

                                //币种
                                page.getEditBox().getExtField('currency').setComboValue(resp.rows[0].currency,resp.rows[0].currencyName);
                                tempFields.put('currencyName', resp.rows[0].currencyName);

                                //汇率
                                C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            page.getEditBox().setValue('exchangeRate',resp);
                                        });

                                //是否增值税
                                if(resp.rows[0].currency == 'CNY')
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()

                                //税率
                                if(resp.rows[0].taxRate||resp.rows[0].taxRate==0)
                                    page.getEditBox().setValue("taxRate",resp.rows[0].taxRate.toString());

                                //不含税金额
                                if(resp.rows[0].amountWithoutTax){
                                    page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(resp.rows[0].amountWithoutTax);  //
                                    page.getEditBox().getExtField('amountWithoutTax').setValue(resp.rows[0].amountWithoutTax);  //不含税总额
                                }

                                //税额
                                if(resp.rows[0].taxAmount==0){
                                    page.getEditBox().getExtField('dtlTaxAmount').setValue(resp.rows[0].taxAmount);
                                    page.getEditBox().getExtField('taxAmount').setValue(resp.rows[0].taxAmount);
                                }
                                //含税金额
                                if(resp.rows[0].fare){
                                    page.getEditBox().getExtField('dtlAmount').setValue(resp.rows[0].fare);
                                    page.getEditBox().getExtField('amount').setValue(resp.rows[0].fare);
                                }
                                //人民币金额
                                if(resp.rows[0].baseAmount)
                                    page.getEditBox().getExtField('baseAmount').setValue(resp.rows[0].baseAmount);


                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].vendor},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })
                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                            }
                        })
            }

            function GDaddBjorder(){
                C.syncRequest.callAction('list','engsaveOrder',{_extend:" and engsaveId= '"+completionReportId +"'"} ,
                    function(action, domainName, resp){
                        if(resp.total>0) {
                            //根据查询的航修申请数据绑定发票录入的默认值
                            page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName)
                            //单号
                            page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].woorder)
                            //王工日期
                            page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].wodate)
                            //开票单位
                            page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].vendor,resp.rows[0].vendorname);
                            //审计文号
                            page.getEditBox().getExtField("auditNo").setValue(resp.rows[0].auditNo);

                            //费用类别
                            page.getEditBox().getExtField("invoiceSort").setComboValue("FY98","节能减排费");

                            //费用科目
                            page.getEditBox().getExtField("invoiceSortDetail").setComboValue("FY98001","节能减排费");
                            tempFields.put('vesselName', resp.rows[0].vesselName);
                            tempFields.put('payeeName', resp.rows[0].repairFactoryName);

                            var vesselManagement=  getManagementByVesselCode(resp.rows[0].vesselCode);

                            //费用流向业务逻辑
                            C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                function(action,domainName,resp){
                                    if(resp.total>0){
                                        page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                    }
                                })

                            //付款单位
                            setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')

                            //船
                            C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                if(resp&&resp.rows&&resp.rows.length>0){
                                    var rs = resp.rows[0]
                                    var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                    var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                    if(!isEmpty(director)){
                                        page.getEditBox().getExtField("director").setValue(director);
                                    }else{
                                        page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                    }
                                    tempFields.put('usrName', rs.engineManagerName);
                                    page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                    tempFields.put('departmentName', rs.manageDeptName);
                                }
                            });

                            //币种
                            page.getEditBox().getExtField('currency').setComboValue(resp.rows[0].currency,resp.rows[0].currencyName);
                            tempFields.put('currencyName', resp.rows[0].currencyName);

                            //汇率
                            C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                function(action,domainName,resp){
                                    page.getEditBox().setValue('exchangeRate',resp);
                                });
                            //是否增值税
                            if(resp.rows[0].currency == 'CNY')
                                page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()
                            //税率
                            if((!resp.rows[0].taxRate)||resp.rows[0].taxRate==0)
                                page.getEditBox().setValue("taxRate",0);
                                page.getEditBox().getExtField('taxAmount').setReadOnly(true);
                            //不含税金额
                            if(resp.rows[0].fareTotal){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(resp.rows[0].fareTotal);  //
                                page.getEditBox().getExtField('amountWithoutTax').setValue(resp.rows[0].fareTotal);  //不含税总额
                            }
                            //税额
                            if(resp.rows[0].dtlTaxAmt==0){
                                page.getEditBox().getExtField('dtlTaxAmount').setValue(resp.rows[0].dtlTaxAmt);
                                page.getEditBox().getExtField('taxAmount').setValue(resp.rows[0].dtlTaxAmt);
                            }
                            //含税金额
                            if(resp.rows[0].amtVend){
                                page.getEditBox().getExtField('dtlAmount').setValue(resp.rows[0].amtVend);
                                page.getEditBox().getExtField('amount').setValue(resp.rows[0].amtVend);
                            }
                            //人民币金额
                            if(resp.rows[0].baseAmount)
                                page.getEditBox().getExtField('baseAmount').setValue(resp.rows[0].disVendCny);
                            //费用流向业务逻辑
                            C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                function(action,domainName,resp){
                                    if(resp.total>0){
                                        page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                    }
                                })
                            //付款单位
                            setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                        }
                    })
            }

            function HXaddBjorder(){

                C.syncRequest.callAction('list','repairAudit',{_extend:" and repairAuditId= '"+completionReportId +"'"} ,
                        function(action, domainName, resp){
                            if(resp.total>0) {
                                //根据查询的航修申请数据绑定发票录入的默认值
                                page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName)
                                //单号
                                page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].projectNo)
                                //王工日期
                                page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].compDate)
                                //开票单位
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].repairFactory,resp.rows[0].repairFactoryName);
                                //审计文号
                                page.getEditBox().getExtField("auditNo").setValue(resp.rows[0].auditNo);

                                tempFields.put('vesselName', resp.rows[0].vesselName);
                                tempFields.put('payeeName', resp.rows[0].repairFactoryName);

                                var vesselManagement=  getManagementByVesselCode(resp.rows[0].vesselCode);
                                //航修申请单独的修理小类以及修理类别的绑定值
                                //1根据repairMainID repairMainVo
                                C.syncRequest.callAction("list","repairMainVo",{repairMainId:resp.rows[0].repairMainId},function(actionName, domainName, resp){
                                    if(resp.total>0) { //费用类别和费用小类业务逻辑
                                        var codeValueStr = "'"+vesselManagement+"','00000000'";
                                        var vess_sort_codeValue="";
                                        var vess_sort_display="";
                                        var jt_sort_codeValue="";
                                        var jt_sort_display="";
                                        C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_SORT",codeValue:resp.rows[0].repairType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp1){
                                            if(resp1&&resp1.rows.length>0){
                                                Ext.each(resp1.rows,function(v){
                                                    if(v.displayValueExtraEn==vesselManagement){
                                                        vess_sort_codeValue = v.codeValue;
                                                        vess_sort_display = v.displayValueCn;
                                                    }
                                                    if(v.displayValueExtraEn=="00000000"){
                                                        jt_sort_codeValue = v.codeValue;
                                                        jt_sort_display = v.displayValueCn;
                                                    }
                                                })
                                            }
                                        })
                                        if(!isEmpty(vess_sort_codeValue)){
                                            page.getEditBox().getExtField("invoiceSort").setComboValue(vess_sort_codeValue,vess_sort_display);
                                            tempFields.put('freightTypeName',vess_sort_display);
                                        }else{
                                            page.getEditBox().getExtField("invoiceSort").setComboValue(jt_sort_codeValue,jt_sort_display);
                                            tempFields.put('freightTypeName',jt_sort_display);
                                        }
                                        var vess_detail_codeValue="";
                                        var vess_detail_display="";
                                        var jt_detail_codeValue="";
                                        var jt_detail_display="";
                                        C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_COURSE",codeValue:resp.rows[0].repairSmallType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp3){
                                            if(resp3&&resp3.rows.length>0){
                                                Ext.each(resp3.rows,function(v){
                                                    if(v.displayValueExtraEn==vesselManagement){
                                                        vess_detail_codeValue = v.codeValue;
                                                        vess_detail_display = v.displayValueCn;
                                                    }
                                                    if(v.displayValueExtraEn=="00000000"){
                                                        jt_detail_codeValue = v.codeValue;
                                                        jt_detail_display = v.displayValueCn;
                                                    }
                                                })
                                            }
                                        })
                                        if(!isEmpty(vess_detail_codeValue)){
                                            page.getEditBox().getExtField("invoiceSortDetail").setComboValue(vess_detail_codeValue,vess_detail_display);
                                            tempFields.put('freightName',vess_detail_display);
                                        }else{
                                            page.getEditBox().getExtField("invoiceSortDetail").setComboValue(jt_detail_codeValue,jt_detail_display);
                                            tempFields.put('freightName',jt_detail_display);
                                        }
                                    }
                                })
                                var invoiceSortDetailVal=page.getEditBox().getExtField("invoiceSortDetail").getComboValue();
                                if(invoiceSortDetailVal&&invoiceSortDetailVal.display.startWith('FY')){
                                    page.getEditBox().getExtField("invoiceSortDetail").setComboValue("","");
                                    tempFields.put('freightName',"");
                                }
                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })

                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')

                                //船
                                C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                        var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                        tempFields.put('usrName', rs.engineManagerName);
                                        page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                        tempFields.put('departmentName', rs.manageDeptName);
                                    }
                                });


                                //币种
                                page.getEditBox().getExtField('currency').setComboValue(resp.rows[0].currency,resp.rows[0].currencyName);
                                tempFields.put('currencyName', resp.rows[0].currencyName);

                                //汇率
                                C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            page.getEditBox().setValue('exchangeRate',resp);
                                        });

                                //是否增值税
                                if(resp.rows[0].currency == 'CNY')
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()

                                //税率
                                if(resp.rows[0].taxRate||resp.rows[0].taxRate==0)
                                    page.getEditBox().setValue("taxRate",resp.rows[0].taxRate.toString());

                                //不含税金额
                                if(resp.rows[0].dtlAmtWithoutTax){
                                    page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(resp.rows[0].dtlAmtWithoutTax);  //
                                    page.getEditBox().getExtField('amountWithoutTax').setValue(resp.rows[0].dtlAmtWithoutTax);  //不含税总额
                                }

                                //税额
                                if(resp.rows[0].dtlTaxAmt==0){
                                    page.getEditBox().getExtField('dtlTaxAmount').setValue(resp.rows[0].dtlTaxAmt);
                                    page.getEditBox().getExtField('taxAmount').setValue(resp.rows[0].dtlTaxAmt);
                                }
                                //含税金额
                                if(resp.rows[0].amtVend){
                                    page.getEditBox().getExtField('dtlAmount').setValue(resp.rows[0].amtVend);
                                    page.getEditBox().getExtField('amount').setValue(resp.rows[0].amtVend);
                                }
                                //人民币金额
                                if(resp.rows[0].baseAmount)
                                    page.getEditBox().getExtField('baseAmount').setValue(resp.rows[0].disVendCny);


                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })
                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')
                            }
                        })
            }
            function HXZJaddorder(){  //航修总结
                C.syncRequest.callAction('list','vwVrmVoyageSummary',{_extend:" and completionReportId= '"+completionReportId +"'"} ,
                        function(action, domainName, resp){
                            if(resp.total>0) {
                                //根据查询的通导工单数据绑定发票录入的默认值
                                page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName);
                                page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].projectNo)  //带工程单号
                                page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].planFactDate)
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].repairFactory,resp.rows[0].repairFactoryName)
                                tempFields.put('vesselName', resp.rows[0].vesselName);
                                tempFields.put('payeeName', resp.rows[0].vendorName);

                                var vesselManagement=  getManagementByVesselCode(resp.rows[0].vesselCode);
                                //费用类别和费用小类业务逻辑
                                var codeValueStr = "'"+vesselManagement+"','00000000'";
                                var vess_sort_codeValue="";
                                var vess_sort_display="";
                                var jt_sort_codeValue="";
                                var jt_sort_display="";
                                C.syncRequest.callAction("listby_szz","codedict",{codeType:"FMM_INVOICE_SORT",codeValue:resp.rows[0].repairType,displayValueExtraEn:codeValueStr },function(actionName, domainName, resp1){
                                    if(resp1&&resp1.rows.length>0){
                                        Ext.each(resp1.rows,function(v){
                                            if(v.displayValueExtraEn==vesselManagement){
                                                vess_sort_codeValue = v.codeValue;
                                                vess_sort_display = v.displayValueCn;
                                            }
                                            if(v.displayValueExtraEn=="00000000"){
                                                jt_sort_codeValue = v.codeValue;
                                                jt_sort_display = v.displayValueCn;
                                            }
                                        })
                                    }
                                })
                                if(!isEmpty(vess_sort_codeValue)){
                                    page.getEditBox().getExtField("invoiceSort").setComboValue(vess_sort_codeValue,vess_sort_display);
                                    tempFields.put('freightTypeName',vess_sort_display);
                                }else{
                                    page.getEditBox().getExtField("invoiceSort").setComboValue(jt_sort_codeValue,jt_sort_display);
                                    tempFields.put('freightTypeName',jt_sort_display);
                                }
                                //船
                                C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                        var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                        tempFields.put('usrName', rs.engineManagerName);
                                        page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                        tempFields.put('departmentName', rs.manageDeptName);
                                    }
                                });
                                //币种
                                if(resp.rows[0].currency){
                                    page.getEditBox().getExtField('currency').setValue(resp.rows[0].currency);
                                    C.ajax.callAction('list','currency',{currency:resp.rows[0].currency},
                                            function(action,domainName,resp){
                                                if(resp&&resp.rows){
                                                    tempFields.put('currencyName', resp.rows[0].currencyName);
                                                    page.getEditBox().getExtField('currency').setComboValue(resp.rows[0].currency,resp.rows[0].currencyName);
                                                }
                                            });
                                }
                                //汇率
                                C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:resp.rows[0].currency,currencyTo:'CNY'},
                                        function(action,domainName,resp){
                                            page.getEditBox().setValue('exchangeRate',resp);
                                        });

                                //是否增值税
                                if(resp.rows[0].currency == 'CNY')
                                    page.getEditBox().getExtField('ifCanUseTax').setValue("1");//触发setFieldDisabledCommon()

                                //税率
                                if(resp.rows[0].taxRate||resp.rows[0].taxRate==0)
                                    page.getEditBox().setValue("taxRate",resp.rows[0].taxRate.toString());

                                //不含税金额
                                if(resp.rows[0].dtlAmountWithoutTax){
                                    page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(resp.rows[0].dtlAmountWithoutTax);  //
                                    page.getEditBox().getExtField('amountWithoutTax').setValue(resp.rows[0].dtlAmountWithoutTax);  //不含税总额
                                }

                                //税额
                                if(resp.rows[0].dtlTaxAmount==0){
                                    page.getEditBox().getExtField('dtlTaxAmount').setValue(resp.rows[0].dtlTaxAmount);
                                    page.getEditBox().getExtField('taxAmount').setValue(resp.rows[0].dtlTaxAmount);
                                }
                                //含税金额
                                if(resp.rows[0].finishedCost){
                                    page.getEditBox().getExtField('dtlAmount').setValue(resp.rows[0].finishedCost);
                                    page.getEditBox().getExtField('amount').setValue(resp.rows[0].finishedCost);
                                }
                                //人民币金额
                                if(resp.rows[0].planActualCost)
                                    page.getEditBox().getExtField('baseAmount').setValue(resp.rows[0].planActualCost);

                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairFactory},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })
                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')

                            }
                        })
            }
            function HXTDaddBjorder() {
                C.syncRequest.callAction('list', 'shipGuideVo', {_extend: " and shipGuideId= '" + completionReportId + "'"},
                        function (action, domainName, resp) {
                            if (resp.total > 0) {
                                //根据查询的航修通导数据绑定发票录入的默认值
                                page.getEditBox().getExtField("vesselCode").setComboValue(resp.rows[0].vesselCode, resp.rows[0].vesselName)
                                //单号invoiceSort
                                page.getEditBox().getExtField("innerOrder").setValue(resp.rows[0].oddNumber)
                                //王工日期
                                page.getEditBox().getExtField("occurTimeFrom").setValue(resp.rows[0].completeDate)
                                //开票单位
                                page.getEditBox().getExtField("payee").setComboValue(resp.rows[0].repairCompany,resp.rows[0].repairCompanyName)

                                tempFields.put('vesselName', resp.rows[0].vesselName);
                                tempFields.put('payeeName', resp.rows[0].repairFactoryName);
                                page.getEditBox().getExtField("safeFlag").setValue(resp.rows[0].isSafeprod)

                                //费用流向业务逻辑
                                C.ajax.callAction('list','customerGridVo',{customerCode:resp.rows[0].repairCompany},
                                        function(action,domainName,resp){
                                            if(resp.total>0){
                                                page.getEditBox().getExtField("feeFlow").setComboValue(resp.rows[0].chargeFlow,resp.rows[0].chargeFlow);
                                            }
                                        })

                                //付款单位
                                setInvoicePayer(resp.rows[0].vesselCode,new Date(),'6','<%=user.getCompanyCode()%>')

                                //船
                                C.ajax.callAction('list','vesselGridVo',{vesselCode:resp.rows[0].vesselCode},function(a,b,resp){
                                    if(resp&&resp.rows&&resp.rows.length>0){
                                        var rs = resp.rows[0]
                                        var selectFreightType = page.getEditBox().getExtField("invoiceSort").getValue();
                                        var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                                        var director =  getDirector(selectFreightType,companyCode,vesselCode);
                                        if(!isEmpty(director)){
                                            page.getEditBox().getExtField("director").setValue(director);
                                        }else{
                                            page.getEditBox().getExtField("director").setComboValue(rs.engineManager,rs.engineManagerName);
                                        }
                                        tempFields.put('usrName', rs.engineManagerName);
                                        page.getEditBox().getExtField("department").setComboValue(rs.manageDept,rs.manageDeptName);
                                        tempFields.put('departmentName', rs.manageDeptName);
                                    }
                                });


                            }
                        })
            }
            function doSaveBJ(){
                var lis = []
                var selectRecord = vwFmmSpsPurGridDomain.getDataSource().getGridAllRecords();
                Ext.each(selectRecord,function(v){
                    var rec = v.data;
                    var newRec = {
                        feeInvoiceId:currentRecord.feeInvoiceId,
                        paymentNoticeId:currentRecord.paymentNoticeId,
                        invoiceStatus:currentRecord.invoiceStatus,
                        relatedId:rec.relatedId,
                        relatedName:'备件',
                        vesselCode:rec.vesselCode,
                        vesselName:rec.vesselName,
                        materialNo:rec.materialNo,
                        materialName:rec.materialName,
                        classNo:rec.equipNo,
                        className:rec.className,
                        parentId:rec.parentId,
                        activityTypeDetail:rec.activityTypeDetail,
                        activityDate:rec.activityDate,
                        qty:rec.qty,
                        supplierCode:rec.supplierCode,
                        currency:rec.currency,
                        currencyName: rec.currencyName?rec.currencyName:currentRecord.currencyName,
                        rate:rec.rate,
                        relatedAmount:rec.relatedAmount,
                        relatedAmountWithoutTax:rec.relatedAmountWithoutTax,
                        taxRate:rec.taxRateName,
                        taxAmount:rec.taxAmount,
                        taxRateName:rec.taxRateName,
                        cnyExchangeRate:rec.cnyExchangeRate,
                        cnyFee:rec.cnyFee,
                        cnyFeeWithoutTax:round(Number(rec.relatedAmountWithoutTax)*Number(rec.cnyExchangeRate),2),
                        cnyTax:round(Number(rec.cnyFee)*Number(rec.taxRateName),2),
                        cnyPrice:rec.invoiceAmount,
                        supplierName:rec.supplierName,
                        equipModel:rec.equipModel,
                        activityTypeDetailName:rec.cwbtName,
                        auditQty:rec.qty,
                        noAuditQty:0,
                        remark:rec.remark,
                        invoiceAmount:currentRecord.invoiceAmount,
                        invoiceAmountWithoutTax:currentRecord.invoiceAmountWithoutTax,
                        invoiceTax:currentRecord.invoiceAmountWithoutTax,
                        applyConfirmId : rec.applyConfirmId,
                        relateOrderNo : rec.cwbtCode     //把流水订单号的值赋值给relateOrderNo
                    }
                    if(rec.relatedId!=null&&rec.relatedId!=''){
                        lis.push(newRec)
                    }
                })
                var sailDatas = Ext.JSON.encode(lis);
                //新增保存的时候需要判断关联信息是否有记录才能更改是否挂单状态，否则没有记录保存成功也会更改是否挂单状态
                if(!isEmpty(lis)){
                    C.ajax.callAction("batch", 'operationRelevance', {batch: sailDatas},
                            function(action,domainName,resp) {
                                tempRecordLists = [];//清空list
                                //保存完子表，将主表projectName保存为已挂单
                                if(resp.success){
                                    C.ajax.callAction('setRelated', 'feeInvoice', {feeInvoiceId: currentRecord.feeInvoiceId}, function () {
                                        C.context.register('feeInvoiceBack', {saved: true});
                                    });
                                }
                            });
                }
            }
            function doSaveTD(){//航修通导订购
                var selectRecord = vwFmmVrmShipGuideQueryDomain2 .getDataSource().getGridAllRecords();
                var i=0;
                if(selectRecord[i]==null){
                    return;
                }
                var relatedId = selectRecord[i].data.relatedId;
                var relatedName = selectRecord[i].data.relatedName?selectRecord[i].data.relatedName:"修船通导";
                var qty = 0;
                var relatedAmount = (selectRecord[i].data.rate?selectRecord[i].data.rate:0);
                var parentId = 'xax';
                var vesselCode = (selectRecord[i].data.vesselCode?selectRecord[i].data.vesselCode:'');
                var portCode = (selectRecord[i].data.portCode?selectRecord[i].data.portCode:'');
                var price = 0;
                var remark = (selectRecord[i].data.remark?selectRecord[i].data.remark:'');
                var taxRate = '0.17'
                var taxAmount = (selectRecord[i].data.rate?Ext.util.Format.round((0.17*selectRecord[i].data.rate),2):0);
                var activityDate = selectRecord[i].data.activityDate?dateFormat(selectRecord[i].data.activityDate,'yyyy-MM-dd'):'';
                var supplierCode = selectRecord[i].data.supplierCode?selectRecord[i].data.supplierCode:'';
                var auditedFlag = selectRecord[i].data.auditedFlag?selectRecord[i].data.auditedFlag:'';
                var materialNo = selectRecord[i].data.materialNo?selectRecord[i].data.materialNo:'';
                var materialName = selectRecord[i].data.materialName?selectRecord[i].data.materialName:'';
                var classNo = selectRecord[i].data.classNo?selectRecord[i].data.classNo:'';
                var className = selectRecord[i].data.className?selectRecord[i].data.className:'';
                i++;
                while(selectRecord[i]){
                    relatedId += "," + selectRecord[i].data.relatedId;
                    relatedName += "," + (selectRecord[i].data.relatedName?selectRecord[i].data.relatedName:"航修通导");
                    qty += "," + 0;
                    relatedAmount += "," +(selectRecord[i].data.relatedAmount?selectRecord[i].data.relatedAmount:0);
                    parentId += "," + 'xax';
                    vesselCode += "," + (selectRecord[i].data.vesselCode?selectRecord[i].data.vesselCode:'');
                    portCode += ","+ (selectRecord[i].data.portCode?selectRecord[i].data.portCode:'');
                    price += "," + 0;
                    remark += "," + (selectRecord[i].data.remark?selectRecord[i].data.remark:'');
                    taxRate += "," + '0.17';
                    taxAmount += "," + (selectRecord[i].data.taxAmount?Ext.util.Format.round((0.17*selectRecord[i].data.taxAmount),2):0);
                    activityDate += "," + (selectRecord[i].data.completeDate?dateFormat(selectRecord[i].data.completeDate,'yyyy-MM-dd'):'');
                    supplierCode += "," + (selectRecord[i].data.repairCompany?selectRecord[i].data.repairCompany:'');
                    auditedFlag += ","+ (selectRecord[i].data.auditedFlag?selectRecord[i].data.auditedFlag:'');
                    materialNo += ","+ (selectRecord[i].data.materialNo?selectRecord[i].data.materialNo:'');
                    materialName += ","+ (selectRecord[i].data.materialName?selectRecord[i].data.materialName:'');
                    classNo += "," + (selectRecord[i].data.classNo?selectRecord[i].data.classNo:'');
                    className += "," + (selectRecord[i].data.className?selectRecord[i].data.className:'');
                    i++;
                }
                //新增保存的时候需要判断关联信息是否有记录才能更改是否挂单状态，否则没有记录保存成功也会更改是否挂单状态
                if(!isEmpty(selectRecord)){
                    C.ajax.callAction('save','operationRelevance',{
                                feeInvoiceId:currentRecord.feeInvoiceId,
                                paymentNoticeId:currentRecord.paymentNoticeId,
                                vesselCode:currentRecord.vesselCode,
                                vesselName:currentRecord.vesselName,
                                relatedId:relatedId,
                                relatedName:relatedName,
                                qty:qty,
                                num:i,
                                relatedAmount:relatedAmount,
                                vesselCodes:vesselCode,
                                portCode:portCode,
                                price:price,
                                currency:currentRecord.currency,
                                invoiceAmount:currentRecord.invoiceAmount,
                                invoiceStatus:currentRecord.invoiceStatus,
                                parentId:parentId,
                                remark:remark,
                                taxRate:taxRate,
                                taxAmount:taxAmount,
                                activityDate:activityDate,
                                supplierCode:supplierCode,
                                auditedFlag:auditedFlag,
                                materialNo:materialNo,
                                materialName:materialName,
                                classNo:classNo,
                                className:className
                            },
                            function(action,domainName,resp){
                                tempRecordLists = [];//清空list
                                //保存完子表，将主表projectName保存为已挂单
                                C.ajax.callAction('setRelated','feeInvoice',{feeInvoiceId:currentRecord.feeInvoiceId},function(){
                                    C.context.register('feeInvoiceBack',{saved:true});
                                });
                            });
                }
            }
            function doSaveWL(){
                var lis = []
                var selectRecord = vwFmmMtrPurGridDomain.getDataSource().getGridAllRecords();
                Ext.each(selectRecord,function(v){
                    var rec = v.data
                    var newRec = {
                        feeInvoiceId:currentRecord.feeInvoiceId,
                        paymentNoticeId:currentRecord.paymentNoticeId,
                        invoiceStatus:currentRecord.invoiceStatus,
                        relatedId:rec.relatedId,
                        relatedName:'备件',
                        vesselCode:rec.vesselCode,
                        vesselName:rec.vesselName,
                        materialNo:rec.materialNo,
                        materialName:rec.materialName,
                        classNo:rec.equipNo,
                        className:rec.className,
                        parentId:rec.parentId,
                        activityTypeDetail:rec.activityTypeDetail,
                        activityDate:rec.activityDate,
                        qty:rec.qty,
                        supplierCode:rec.supplierCode,
                        currency:rec.currency,
                        currencyName: rec.currencyName?rec.currencyName:currentRecord.currencyName,
                        rate:rec.rate,
                        relatedAmount:rec.relatedAmount,
                        relatedAmountWithoutTax:rec.relatedAmountWithoutTax,
                        taxRate:rec.taxRateName,
                        taxAmount:rec.taxAmount,
                        taxRateName:rec.taxRateName,
                        cnyExchangeRate:rec.cnyExchangeRate,
                        cnyFee:rec.cnyFee,
                        cnyFeeWithoutTax:round(Number(rec.relatedAmountWithoutTax)*Number(rec.cnyExchangeRate),2),
                        cnyTax:round(Number(rec.cnyFee)*Number(rec.taxRateName),2),
                        cnyPrice:rec.invoiceAmount,
                        supplierName:rec.supplierName,
                        equipModel:rec.equipModel,
                        activityTypeDetailName:rec.cwbtName,
                        auditQty:rec.qty,
                        noAuditQty:0,
                        remark:rec.remark,
                        invoiceAmount:currentRecord.invoiceAmount,
                        invoiceAmountWithoutTax:currentRecord.invoiceAmountWithoutTax,
                        invoiceTax:currentRecord.invoiceAmountWithoutTax,
                        applyConfirmId : rec.applyConfirmId,
                        relateOrderNo : rec.cwbtCode     //把流水订单号的值赋值给relateOrderNo
                    }
                    if(rec.relatedId!=null&&rec.relatedId!=''){
                        lis.push(newRec)
                    }
                })
                var sailDatas = Ext.JSON.encode(lis);
                //新增保存的时候需要判断关联信息是否有记录才能更改是否挂单状态，否则没有记录保存成功也会更改是否挂单状态
                if(!isEmpty(lis)){
                    C.ajax.callAction("batch", 'operationRelevance', {batch: sailDatas},
                            function(action,domainName,resp) {
                                tempRecordLists = [];//清空list
                                //保存完子表，将主表projectName保存为已挂单
                                C.ajax.callAction('setRelated', 'feeInvoice', {feeInvoiceId: currentRecord.feeInvoiceId}, function () {
                                    C.context.register('feeInvoiceBack', {saved: true});
                                });
                            });
                }
            }
            var clickText = "";
            //根据订单号改变值
            function innerOrderTypeBox(innerOrderStr,conMets) {
                if(innerOrderStr!=""&&conMets!=null){
                    var window =Ext.create('Ext.window.Window', {
                        width: 300,
                        height: 120,
                        layout: 'border',
                        closable:false,
                        title: CSIS.Lang.ID_117530||"提示",
                        modal: true,
                        items: [{
                                xtype: 'label',
                                name:'infoLabel',
                                text:(CSIS.Lang.ID_140200||"订单")+innerOrderStr+(CSIS.Lang.ID_140210||"，发票是否来齐？"),
                                padding: "16px 0px 0px 25px",
                                labelAlign:'center'
                            }],
                        buttons: [{
                                text: CSIS.Lang.ID_107640||'是',
                                handler: function () {
                                    clickText = CSIS.Lang.ID_107640||"是";
                                    for(var i=0;i<conMets.length;i++){
                                        C.ajax.callAction(conMets[i].method,conMets[i].controller,{innerOrder:innerOrderStr,status:2},
                                                function(action,domain,resp){})
                                    }
                                    window.close()
                                }
                            },{
                                text: CSIS.Lang.ID_107650||'否',
                                handler: function () {
                                    clickText = CSIS.Lang.ID_107650||"否";
                                    for(var i=0;i<conMets.length;i++){
                                        C.ajax.callAction(conMets[i].method,conMets[i].controller,{innerOrder:innerOrderStr,status:1},
                                                function(action,domain,resp){})
                                    }
                                    window.close();
                                    return true
                                }
                            }
                        ]
                    })
                    window.show();
                    window.on("close",function(){
                        if(isEmpty(clickText)){
                            for(var i=0;i<conMets.length;i++){
                                C.ajax.callAction(conMets[i].method,conMets[i].controller,{innerOrder:innerOrderStr,status:3},
                                        function(action,domain,resp){})
                            }
                            clickText = "";
                        }
                    });
                }
            }
            //保存后的转码操作
            page.addListener('saved',function(event,rec){
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var innerOrder = page.getEditBox().getExtField('innerOrder').getValue()
                if(!(tianjinFlagTwo && invoiceSort == 'FY63' && !isEmpty(innerOrder))){
                    var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                    if (invoiceSort == 'FY01' || invoiceSort == 'FY02' || invoiceSort == 'FY62' || invoiceSort == 'FY63' || invoiceSort == 'FY64' || invoiceSort == 'FY67' || invoiceSort == 'FY61' || invoiceSort == 'FY05' || invoiceSort == 'FY69'
                            || invoiceSort == 'FY77' || invoiceSort == 'FY41' || invoiceSort == 'FY78' || invoiceSort == 'FY79' || invoiceSort == 'FY80'||(youlunFlag&&invoiceSort == 'FY13')
                            || invoiceSort == 'FY81' || invoiceSort == 'FY82' || invoiceSort == 'FY83' || invoiceSort == 'FY84' || invoiceSort == 'FY85' || invoiceSort == 'FY86' || invoiceSort == 'FY87' || invoiceSort == 'FY88' || invoiceSort == 'FY97' || invoiceSort == 'FY56') {
                        if (invoiceSortDetail == 'FY01003' || invoiceSortDetail == 'FY01004' || invoiceSortDetail == 'FY64001' ||
                                invoiceSortDetail == 'FY02003' || invoiceSortDetail == 'FY02004' || invoiceSort == 'FY63'||invoiceSort=='ZCF'
                        || invoiceSortDetail == 'FY56001' ) {//备件订购
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [{controller: "applyConfirm", method: "updateIfPaid"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        }else if(youlunFlag&&(invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'||invoiceSort=='FY13')){
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [{controller: "completionReport", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++)innerOrderTypeBox(innerOrders[i], conMets);
                        } else if (invoiceSort == 'FY67') {
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [ {controller: "shipGuideVo", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                            var conMets = [{controller: "completionReport", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        } else if (invoiceSortDetail == 'FY01002' || invoiceSortDetail == 'FY01005' || invoiceSortDetail == 'FY01007' || invoiceSort == 'FY67') { //航修通导订购
                            //VRM_COMPLETION_REPORT、FMM_SHIP_GUIDE
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [ {controller: "shipGuideVo", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        } else if (invoiceSort == 'FY81' || invoiceSort == 'FY82' || invoiceSort == 'FY83' || invoiceSort == 'FY84' || invoiceSort == 'FY85' || invoiceSort == 'FY86' || invoiceSort == 'FY87' || invoiceSort == 'FY88') {  //
                            //通导表vrm_workorder
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [{controller: "vrmWorkorder", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        } else if (invoiceSort == 'FY61' || invoiceSort == 'FY62' || invoiceSortDetail == 'FY64001' || invoiceSort == 'FY05' || invoiceSort == 'FY77' || invoiceSort == 'FY41' || invoiceSort == 'FY78' || invoiceSort == 'FY79' || invoiceSort == 'FY80' || invoiceSort == 'FY97'
                            || invoiceSortDetail == 'FY56002'|| invoiceSortDetail == 'FY56003') {
                            //维修VRM_COMPLETION_REPORT
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [{controller: "completionReport", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        } else {
                            var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                            var innerOrders = innerOrderStr.split(",");
                            var conMets = [{controller: "completionReport", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) {
                                innerOrderTypeBox(innerOrders[i], conMets);
                            }
                        }
                    } else if ((companyCode.startWith('65')&&invoiceSort == 'FY28')||invoiceSort == 'FY04' || invoiceSort == 'FY33' || invoiceSort == 'FY65' || invoiceSort == 'FY66'|| invoiceSort == 'FY58') {//
                        //物料订购  mtr_apply_confirm_mtr
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        var conMets = [{controller: "applyConfirmMtr", method: "updateIfPaidAll"}];
                        for (i = 0; i < innerOrders.length; i++) {
                            innerOrderTypeBox(innerOrders[i], conMets);
                        }
                    }else if (bndFlag) {
                        //绑垫料
                        var requestDomain = "bandApplyConfirm"
                        if (invoiceSort == 'FYRG') {
                            requestDomain = 'bandServiceApplyMain';
                        }
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        var conMets = [{controller: requestDomain, method: "updateIfPaidAll"}];
                        for (i = 0; i < innerOrders.length; i++) {
                            innerOrderTypeBox(innerOrders[i], conMets);
                        }
                    } else if (invoiceSort == 'FY98'){
                        //物料订购  mtr_apply_confirm_mtr
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        var conMets = [{controller: "engsaveOrder", method: "updateIfPaidAll"}];
                        for (i = 0; i < innerOrders.length; i++) {
                            innerOrderTypeBox(innerOrders[i], conMets);
                        }
                    }else  if(youlunFlag&&invoiceSort == 'FY06'){
                        var srcOrderType = page.getEditBox().getExtField('srcOrderType').getValue();
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        if(srcOrderType=='0'||srcOrderType=='4'||srcOrderType=='5'||srcOrderType=='6'||srcOrderType=='16'){  //修理
                            var conMets = [{controller: "completionReport", method: "updateIsInvoice"}];
                            for (i = 0; i < innerOrders.length; i++) { innerOrderTypeBox(innerOrders[i], conMets); }
                        }else if(srcOrderType=='1'||srcOrderType=='3'||srcOrderType=='13'||srcOrderType=='17'){//物料
                            var conMets = [{controller: "applyConfirmMtr", method: "updateIfPaidAll"}];
                            for (i = 0; i < innerOrders.length; i++) {innerOrderTypeBox(innerOrders[i], conMets); }
                        }else if(srcOrderType=='2'||srcOrderType=='18'){//备件
                            var conMets = [{controller: "applyConfirm", method: "updateIfPaid"}];
                            for (i = 0; i < innerOrders.length; i++) { innerOrderTypeBox(innerOrders[i], conMets); }
                        }
                    }else  if(invoiceSort == 'FY70'){//add on 210629.
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        var conMets = [{controller: "orderSeachartVo", method: "updateIfPaidAll"}];
                        for (i = 0; i < innerOrders.length; i++) {
                            innerOrderTypeBox(innerOrders[i], conMets);
                        }
                    }if(youlunFlag&&invoiceSort == 'ZCF'){
                        var srcOrderType = page.getEditBox().getExtField('srcOrderType').getValue();
                        var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                        var innerOrders = innerOrderStr.split(",");
                        if(srcOrderType=='11'){//物料
                            var conMets = [{controller: "applyConfirmMtr", method: "updateIfPaidAll"}];
                            for (i = 0; i < innerOrders.length; i++) {innerOrderTypeBox(innerOrders[i], conMets); }
                        }else if(srcOrderType=='8'){//备件
                            var conMets = [{controller: "applyConfirm", method: "updateIfPaid"}];
                            for (i = 0; i < innerOrders.length; i++) { innerOrderTypeBox(innerOrders[i], conMets); }
                        }
                    }
                }
                if (tempFields.size() > 0) {
                    if (tempFields.containsKey('vesselName')) {
                        rec.data.vesselName = tempFields.get('vesselName');
                    }
                    if (tempFields.containsKey('customerName')) {
                        rec.data.customerName = tempFields.get('customerName');
                    }
                    if (tempFields.containsKey('contractName')) {
                        rec.data.contractName = tempFields.get('contractName');
                    }
                    if (tempFields.containsKey('payeeName')) {
                        rec.data.payeeName = tempFields.get('payeeName');
                    }
                    if (tempFields.containsKey('freightName')) {
                        rec.data.freightName = tempFields.get('freightName');
                    }
                    if (tempFields.containsKey('freightTypeName')) {
                        rec.data.freightTypeName = tempFields.get('freightTypeName');
                    }
                    if (tempFields.containsKey('currencyName')) {
                        rec.data.currencyName = tempFields.get('currencyName');
                    }
                    if (tempFields.containsKey('usrName')) {
                        rec.data.usrName = tempFields.get('usrName');
                    }
                    if (tempFields.containsKey('taxRateName')) {
                        rec.data.taxRateName = tempFields.get('taxRateName');
                    }
                    if (tempFields.containsKey('departmentName')) {
                        rec.data.departmentName = tempFields.get('departmentName');
                    }
                    if (tempFields.containsKey('groupSortName')) {
                        rec.data.groupSortName = tempFields.get('groupSortName');
                    }
                    if (tempFields.containsKey('groupSortDetailName')) {
                        rec.data.groupSortDetailName = tempFields.get('groupSortDetailName');
                    }
                    if(tempFields.containsKey('validatePayerCode')){
                        rec.data.payer = tempFields.get('validatePayerCode');
                    }
                    if(tempFields.containsKey('validatePayerName')){
                        rec.data.customerName = tempFields.get('validatePayerName');
                    }
                    if(tempFields.containsKey('safeItemName')){
                        rec.data.safeItemName = tempFields.get('safeItemName');
                    }
                    var safeItem = page.getEditBox().getExtField('safeItem').getValue();
                    if (isEmpty(safeItem)) {
                        rec.data.safeItemName ='';
                    }

                    currentRecord = rec.data;
                    billNoFlag = false//保存后改变标识
                    rec.commit();
                    setComboGrid(page.getEditBox());
                    tempFields.clear();
                }
                isCreate =false;
                //油运的在保存后重新统计人民币总额和人民币不含税金额
                if(!isEmpty(companyCode)&&youlunFlag){
                    var feeInvoiceGridItems = feeInvoiceDomain.getDataSource().data.items;
                    var baseAmountTotal = 0;
                    var baseAmountWithoutTax = 0;
                    for(var i = 0;i<feeInvoiceGridItems.length;i++){
                        baseAmountTotal += Number(feeInvoiceGridItems[i].data.baseAmount);
                        baseAmountWithoutTax += Number(feeInvoiceGridItems[i].data.baseAmountWithoutTax);
                    }
                    Ext.getCmp(baseAmountTotalId).setValue(baseAmountTotal);
                    Ext.getCmp(baseAmountWithoutTaxId).setValue(baseAmountWithoutTax);
                }
                return true;//该语句必须
            });

            var searchParams = null; //用于存在_extend的导出功能
            page.getSearchBox().addListener('search',function(src,val) {
                var searchValue  = page.getSearchBox().getValues();
                if(searchValue.amount!=""){
                    if(_extendParams==''&&searchValue.vesselCode==''){
                        Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息",CSIS.Lang.ID_140220||"输入除发票总金额必须输入船舶！");
                        return
                    }
                }
                var searchSql = searchSumFn(val)

                //新增订单号
                var innerOrderSearch = page.getSearchBox().getValue("innerOrderSearch");
                if(innerOrderSearch){val.innerOrder = innerOrderSearch; }
                val._extend =''
                var iWarn = page.getSearchBox().getValue("isWarn");
                if(iWarn == "1"){
                    val._extend = " AND (inputDate - invoiceDate > 90)";
                }else if(iWarn == "0"){
                    val._extend = " AND (inputDate - invoiceDate <= 90)";
                }
                if(!isEmpty(val.innerOrder)){
                    val._extend += " and  ( mtbl.feeInvoiceId in (select feeInvoiceId from FeeInvoice where  innerOrder LIKE '%" + val.innerOrder+"%')" ;
                    val._extend += "  OR mtbl.feeInvoiceId in ( select feeInvoiceId  from OperationRelevance  op where op.relateOrderNo LIKE  '%"+val.innerOrder+"%')";
                    val._extend += ")";

                    val.innerOrder ="";  //clear again
                }
                if (!isEmpty(val.ytFrom)) {
                    if (val.ytFrom == '0') val._extend += " and nvl(ytFrom,'0')='0' "
                    else if (val.ytFrom == '1') val._extend += " and nvl(ytFrom,'0')='1' "
                    else if (val.ytFrom == '2') val._extend += " and nvl(ytFrom,'0')='2' "
                    delete val.ytFrom;
                }
                var str = val.invoiceStatus.split("|")
                if(val.invoiceStatus != '' && str.length > 0){
                    var status = ''
                    for(var i = 0; i< str.length; i++) {
                        status += "'"+str[i] + "',"
                    }
                    status = status.substring(0,status.length -1)
                    if(status.indexOf('1')!=-1){
                        val._extend += "AND (invoiceStatus is null or invoiceStatus in (" +status+"))"
                    }else{
                        val._extend += "AND invoiceStatus in (" +status+")"
                    }
                    delete val.invoiceStatus;
                }
                //查询区付款单位多选逻辑--
                if(val.payerSearch){
                    var array = val.payerSearch.split('、');
                    val._extend ? (val._extend += " AND payer IN (") : (val._extend = " AND payer IN(");
                    for (var i in array) {
                        val._extend += "'" + array[i] + "',"
                    }
                    val._extend = val._extend.substring(0, val._extend.length - 1) + ")";
                }
                //是否开票
                if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='0200'){
                    var isTickets = page.getSearchBox().getExtField('isTickets').getValue();
                    if(isTickets){
                        if(isTickets == "1"){
                            val._extend += "AND invoiceNo IS NOT NULL"
                        }
                        if(isTickets == "0"){
                            val._extend += "AND invoiceNo IS NULL"
                        }
                        delete val['isTickets']
                    }
                }
                var comboValue = page.getSearchBox().getExtField("vesselCode").getComboValue();
                var s = comboValue.value;
                if(!s){
                    if(val._extend && _extendParams.length>0){
                        val._extend = val._extend + _extendParams;
                    }else if(_extendParams.length>0){
                        val._extend = _extendParams;
                    }
                }
                val._extend  =  val._extend==null?'': val._extend
                if( val["fiReceiveDate.from"] != '') {

                    val._extend += " AND EXISTS(SELECT 1 FROM FeePaymentNotice P " +
                            "WHERE mtbl.paymentNoticeId=P.paymentNoticeId AND" +
                            " P.fiReceiveDate >= TO_DATE('" + val["fiReceiveDate.from"] +"','yyyy-MM-dd'))"
                }
                if( val["fiReceiveDate.to"] != '')  {
                    val._extend += " AND EXISTS(SELECT 1 FROM FeePaymentNotice P " +
                            "WHERE mtbl.paymentNoticeId=P.paymentNoticeId AND" +
                            " P.fiReceiveDate <= TO_DATE('" + val["fiReceiveDate.to"] +"','yyyy-MM-dd HH24:mi:ss'))"
                }
                if( val["finishDate.from"] != ''||val["finishDate.to"] != '') {
                    if( val["finishDate.from"] != '') {
                        val._extend +=" AND sendSapDate >= TO_DATE('" + val["finishDate.from"] +"','yyyy-MM-dd')"
                    }
                    if( val["finishDate.to"] != '')  {
                        val._extend +=  "  AND sendSapDate <= TO_DATE('" + val["finishDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                    }
                }
                if(youlunFlag&&!isEmpty(searchValue.searchVoyageNo)){
                    val.voyageNo = searchValue.searchVoyageNo; delete val['searchVoyageNo'];
                }
                if(youlunFlag&&!isEmpty(searchValue.searchPortCode)){
                    val.portCode = searchValue.searchPortCode; delete val['searchPortCode'];
                }
                if(youlunFlag){
                    val._extend += " AND (crewLumpFeeCalcMainId is null or (crewLumpFeeCalcMainId is not null and paymentNoticeId is not null) ) ";
                }

                if (bndFlag && htwlcgFlag) {
                    val._extend += " AND (mtbl.invoiceSort in ('FY04','FY65','FY27','FY34','FYCL','FYHW','FYRG','FYHF') or mtbl.invoiceSortDetail = 'FY64006')"
                } else if (bndFlag) {
                    val._extend += " AND mtbl.invoiceSort in ('FYCL','FYHW','FYRG','FYHF')"
                } else if (htwlcgFlag) {
                    val._extend += " AND (mtbl.invoiceSort in ('FY04','FY65','FY27','FY34') or mtbl.invoiceSortDetail = 'FY64006')"
                }

                searchParams = val;
                feeInvoiceDomain.getDataSource().loadDataset(val,1);


                //原来方法存在查询重置清空查询所有数据 后台转对象集合再循环相加 百万数据量导致服务器崩溃
                C.ajax.callAction('sumAmount','feeInvoice',val,function(action,domainName,resp){
                    if(resp && resp.success){
                        Ext.getCmp(baseAmountTotalId).setValue(resp.extend.baseAmountTotalId);
                        Ext.getCmp(baseAmountWithoutTaxId).setValue(resp.extend.baseAmountWithoutTaxId)
                        if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='0200'){
                            Ext.getCmp(baseAmountBillQuoteId).setValue(resp.extend.baseAmountBillQuoteId)
                            Ext.getCmp(baseAmountCheckAmountId).setValue(resp.extend.baseAmountCheckAmountId)
                        }
                    }
                });
            })

            function searchSumFn(val){
                var searchSql = " select SUM(MTBL.base_amount),SUM(MTBL.base_amount_without_tax),SUM(MTBL.check_amount),SUM(MTBL.bill_quote) FROM FMM_FEE_INVOICE MTBL where 1=1 " +
                        " and (MTBL.VESSEL_CODE is null or not exists (select 1 from VOP_VESSEL vv where vv.VESSEL_CODE = MTBL.VESSEL_CODE) or exists (select 1 from " +
                        " VW_VOP_VESSEL_MANAGEMENT vvvm where vvvm.VESSEL_CODE_MNGT = MTBL.VESSEL_CODE and current_date " +
                        " between vvvm.DEFINITION_DATE_FROM and vvvm.DEFINITION_DATE_TO)) "

                if(val.invoiceNo){
                    searchSql += " and INVOICE_NO = '"+val.invoiceNo+"' "
                }
                if(val["invoiceDate.from"]){
                    searchSql += " and INVOICE_DATE >= TO_DATE('" + val["invoiceDate.from"] +"','yyyy-MM-dd') "
                }
                if(val["invoiceDate.to"]){
                    searchSql += " and INVOICE_DATE <= TO_DATE('" + val["invoiceDate.to"] +"','yyyy-MM-dd hh24:mi:ss') "
                }
                if(val["payee.eq"]){
                    searchSql += " and payee = '" + val["payee.eq"] +"' "
                }
                if(val["vesselCode"]){
                    searchSql += " and VESSEL_CODE = '" + val["vesselCode"] +"' "
                }
                if(val["inputDate.from"]){
                    searchSql += " and INPUT_DATE >= TO_DATE('" + val["inputDate.from"] +"','yyyy-MM-dd') "
                }
                if(val["inputDate.to"]){
                    searchSql += " and INPUT_DATE <= TO_DATE('" + val["inputDate.to"] +"','yyyy-MM-dd hh24:mi:ss') "
                }
                if(val["department"]){
                    searchSql += " and DEPARTMENT = '" + val["department"] +"' "
                }
                if(val["groupSort"]){
                    searchSql += " and GROUP_SORT = '" + val["groupSort"] +"' "
                }
                if(val["groupSortDetail"]){
                    searchSql += " and GROUP_SORT_DETAIL = '" + val["groupSortDetail"] +"' "
                }
                if(val["invoiceSort"]){
                    searchSql += " and INVOICE_SORT = '" + val["invoiceSort"] +"' "
                }
                if(val["invoiceSortDetail"]){
                    searchSql += " and INVOICE_SORT_DETAIL = '" + val["invoiceSortDetail"] +"' "
                }
                if(val["occurTimeFrom.from"]){
                    searchSql += " and OCCUR_TIME_FROM >= TO_DATE('" + val["occurTimeFrom.from"] +"','yyyy-MM-dd') "
                }
                if(val["occurTimeFrom.to"]){
                    searchSql += " and OCCUR_TIME_FROM <= TO_DATE('" + val["occurTimeFrom.to"] +"','yyyy-MM-dd hh24:mi:ss') "
                }
                if(val["feeFlow"]){
                    searchSql += " and FEE_FLOW = '" + val["feeFlow"] +"' "
                }
                if(val["safeFlag"]){
                    searchSql += " and SAFE_FLAG = '" + val["safeFlag"] +"' "
                }
                if(val["currency"]){
                    searchSql += " and currency = '" + val["currency"] +"' "
                }
                if(val["billNo"]){
                    searchSql += " and BILL_NO = '" + val["billNo"] +"' "
                }
                if(val["ifCanUseTax"]){
                    searchSql += " and IF_CAN_USE_TAX = '" + val["ifCanUseTax"] +"' "
                }
                if(val["ifJigai"]){
                    searchSql += " and IF_JIGAI = '" + val["ifJigai"] +"' "
                }
                if(!youlunFlag && val["isFixedAsset"]){
                    searchSql += " and IS_FIXED_ASSET = '" + val["isFixedAsset"] +"' "
                }
                if(val["amount"]){
                    searchSql += " and amount = '" + val["amount"] +"' "
                }
                if(val["inputUser"]){
                    searchSql += " and INPUT_USER = '" + val["inputUser"] +"' "
                }
                if(val["orderNo"]){
                    searchSql += " and ORDER_NO = '" + val["orderNo"] +"' "
                }
                if(val["isEnergy"]){
                    searchSql += " and IS_ENERGY = '" + val["isEnergy"] +"' "
                }
                if(!youlunFlag && companyCode.substring(0,4)!='0200' && val["isDoubt"]){
                    searchSql += " and IS_DOUBT = '" + val["isDoubt"] +"' "
                }
                if(youlunFlag && val["foreStatMonth"]){
                    searchSql += " and FORE_STAT_MONTH = TO_DATE('" + val["foreStatMonth"] + "-01-01" +"','yyyy-MM-dd') "
                }

                if(val["isWarn"] == "1"){
                    searchSql += " AND (INPUT_DATE - INVOICE_DATE > 90)";
                }else if(val["isWarn"] == "0"){
                    searchSql += " AND (INPUT_DATE - INVOICE_DATE <= 90)";
                }

                if(!isEmpty(val.innerOrder)){
                    searchSql += " and  ( mtbl.FEE_INVOICE_ID in (select FEE_INVOICE_ID from FMM_FEE_INVOICE where  INNER_ORDER LIKE '%" + val.innerOrder+"%')" ;
                    searchSql += "  OR mtbl.FEE_INVOICE_ID in ( select FEE_INVOICE_ID  from FMM_OPERATION_RELEVANCE  op where op.RELATE_ORDER_NO LIKE  '%"+val.innerOrder+"%')";
                    searchSql += ") ";
                }
                if (!isEmpty(val.ytFrom)) {
                    if (val.ytFrom == '0') searchSql += " and nvl(YT_FROM,'0')='0' "
                    else if (val.ytFrom == '1') searchSql += " and nvl(YT_FROM,'0')='1' "
                    else if (val.ytFrom == '2') searchSql += " and nvl(YT_FROM,'0')='2' "
                }
                var str = val.invoiceStatus.split("|")
                if(val.invoiceStatus != '' && str.length > 0){
                    var status = ''
                    for(var i = 0; i< str.length; i++) {
                        status += "'"+str[i] + "',"
                    }
                    status = status.substring(0,status.length -1)
                    if(status.indexOf('1')!=-1){
                        searchSql += "AND (INVOICE_STATUS is null or INVOICE_STATUS in (" +status+"))"
                    }else{
                        searchSql += "AND INVOICE_STATUS in (" +status+")"
                    }
                }
                //查询区付款单位多选逻辑--
                if(val.payerSearch){
                    var array = val.payerSearch.split('、');
                    searchSql ? (searchSql += " AND payer IN (") : (searchSql = " AND payer IN(");
                    for (var i in array) {
                        searchSql += "'" + array[i] + "',"
                    }
                    searchSql = searchSql.substring(0, searchSql.length - 1) + ")";
                }
                //是否开票
                if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='0200'){
                    var isTickets = page.getSearchBox().getExtField('isTickets').getValue();
                    if(isTickets){
                        if(isTickets == "1"){
                            searchSql += "AND INVOICE_NO IS NOT NULL"
                        }
                        if(isTickets == "0"){
                            searchSql += "AND INVOICE_NO IS NULL"
                        }
                    }
                }
                var comboValue = page.getSearchBox().getExtField("vesselCode").getComboValue();
                var s = comboValue.value;
                if(!s){
                    C.syncRequest.callAction("getSelectedCount", 'multiShipSelected', {userCode: userCode,sysid: "",menuNo: menuNo},
                            function (actionName, domainName, resp) {
                                if (resp.success) {
                                    if (parseInt(resp.msg) > 0){
                                        searchSql += " AND EXISTS(select 1 from SYS_MULTI_SHIP_SELECTED mms WHERE mms.VESSEL_CODE=mtbl.VESSEL_CODE " +
                                                " AND mms.USR_CODE ='" + userCode + "' AND mms.menu_No = '" + menuNo + "') "
                                    }
                                }
                            });

                }

                if( val["fiReceiveDate.from"] != '') {

                    searchSql += " AND EXISTS(SELECT 1 FROM FMM_FEE_PAYMENT_NOTICE P " +
                            "WHERE mtbl.PAYMENT_NOTICE_ID=P.PAYMENT_NOTICE_ID AND" +
                            " P.FI_RECEIVE_DATE >= TO_DATE('" + val["fiReceiveDate.from"] +"','yyyy-MM-dd'))"
                }
                if( val["fiReceiveDate.to"] != '')  {
                    searchSql += " AND EXISTS(SELECT 1 FROM FMM_FEE_PAYMENT_NOTICE P " +
                            "WHERE mtbl.PAYMENT_NOTICE_ID=P.PAYMENT_NOTICE_ID AND" +
                            " P.FI_RECEIVE_DATE <= TO_DATE('" + val["fiReceiveDate.to"] +"','yyyy-MM-dd HH24:mi:ss'))"
                }
                if( val["finishDate.from"] != ''||val["finishDate.to"] != '') {
                    if( val["finishDate.from"] != '') {
                        searchSql +=" AND SEND_SAP_DATE >= TO_DATE('" + val["finishDate.from"] +"','yyyy-MM-dd')"
                    }
                    if( val["finishDate.to"] != '')  {
                        searchSql +=  "  AND SEND_SAP_DATE <= TO_DATE('" + val["finishDate.to"] +"','yyyy-MM-dd HH24:mi:ss')"
                    }
                }
                if(youlunFlag&&val['searchVoyageNo']){
                    searchSql += " and VOYAGE_NO = '"+val['searchVoyageNo']+"' ";
                }
                if(youlunFlag&&val['searchPortCode']){
                    searchSql +=  " and PORT_CODE = '"+val['searchPortCode']+"' ";
                }
                if(youlunFlag){
                    searchSql += " AND (CREW_LUMP_FEE_CALC_MAIN_ID is null or (CREW_LUMP_FEE_CALC_MAIN_ID is not null and PAYMENT_NOTICE_ID is not null) ) ";
                }
                if (bndFlag) {
                    extend += " AND mtbl.INVOICE_SORT in ('FYCL','FYHW','FYRG','FYHF')"
                }
                if(val["innerOrderSearch"]){
                    searchSql += " and inner_Order = '"+val["innerOrderSearch"]+"' ";
                }
                return searchSql
            }

            page.getSearchBox().addListener('multiSearch',function(src,val) {
                var win = ShowVesselMultiSelectWin(userCode,"",menuNo);
                win.addListener('closed',function(){
                    var selectedVessels = C.context.get('selectedVessels');
                    C.context.unRegister('selectedVessels');
                    if(!isEmpty(selectedVessels)){
                        _extendParams = selectedVessels;
                    }else{
                        _extendParams = "";
                    }
                });

            });

            function commonListener(record){
                currentRecord = record;//获得当前的行记录
                var eb = page.getEditBox();
                eb.loadRecord(record);
                setComboGrid(eb);
                btnStatusByCurrentRecord(record)
                operationRelevanceDomain.getDataSource().loadDataset({feeInvoiceId:record.feeInvoiceId,limit:1000});
                if(!isEmpty(record.paymentNoticeId)){
                    attachmentDomain.getDataSource().loadDataset({referenceId: record.paymentNoticeId});
                } else {
                    attachmentDomain.getDataSource().loadDataset({referenceIdOne: record.feeInvoiceId});
                }
                refreshPanelVoyageInfoAccessoriesFee(attachmentPanel);
            }

            function btnStatusByCurrentRecord(record){
                if(record.invoiceStatus=='3'|| record.invoiceStatus=='4' || record.invoiceStatus=='5'){
                    page.getToolbarBox().getButton("edit").setDisabled(true);
                    page.getToolbarBox().getButton("remove").disable();
                    btnMainEdit.setDisabled(true);  //add by leo 主界面按钮也灰掉
                    btnMainRemove.setDisabled(true);

                    btnPaymentNotice.setDisabled(true);
                    btnOperation.setDisabled(true);
                }else{
                    setButtonStatus('edit',true)
                    setButtonStatus('remove',true)
                    setButtonStatus('payNoti',true)
                    setButtonStatus('opera',true)
                }
                if (record.invoiceStatus=='4' || record.invoiceStatus=='5') {
                    setButtonStatus('doubtOrRevokeBtn',false)
                } else {
                    setButtonStatus('doubtOrRevokeBtn',true)
                }
                if(!record.invoiceStatus || record.invoiceStatus == '1'){
                    setButtonStatus('payNoti',true);
                    printBtn.setDisabled(true);
                    infoPrintBtn.setDisabled(true);
                }else{
                    btnPaymentNotice.setDisabled(true);
                    printBtn.setDisabled(false);
                    infoPrintBtn.setDisabled(false);
                }

                if(record.isStrike == "1"){
                    btnNegReversal.setDisabled(true)
                }else{
                    setButtonStatus('negRev',true)
                }
                if(record.invoiceStatus=='6' || record.isDoubt=='3'){
                    setButtonStatus('rejectInvoiceBtn',true)
                }else{
                    setButtonStatus('rejectInvoiceBtn',false)
                }
                //能源该字段用于审核退回状态，该状态只允许修改币种，税金，汇率，税率，开票单位
                if(youlunFlag && record.isDoubt=='1'){
                    setButtonStatus('edit',true)
                }
            }


            var vwFmmSpsPurGridDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'feeInvoiceId'},
                {name:'relatedId'},
                {name:'exchangeRate'},
                {name:'cnyExchangeRate'},
                {name:'vesselName',display: CSIS.Lang.ID_100060||'船舶名称',type:'string',readOnly:true},
                {name:'materialNo',display: CSIS.Lang.ID_103170||'备件编号',type:'string',readOnly:true,width:140},
                {name:'equipNo',display: CSIS.Lang.ID_109990||'设备编码',type:'string',readOnly:true,width:140},
                {name:'partsInfoId',display: CSIS.Lang.ID_229470||'备件id',type:'string',readOnly:true},
                {name:'materialName',display: CSIS.Lang.ID_103180||'备件名称',type:'string',readOnly:true,width:140},
                {name:'activityTypeDetail',display: CSIS.Lang.ID_140240||'入库类型',type:'string',readOnly:true},
                {name:'activityDate',display: CSIS.Lang.ID_140250||'入库日期',type:'date',format:'Y-m-d',readOnly:true},
                {name:'qty',display: CSIS.Lang.ID_140260||'开票数量',type:'numbe'},
                {name:'supplierCode',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',type:'string',readOnly:true},
                {name:'rate',display: CSIS.Lang.ID_107420||'单价',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_115370||'金额',type:'number'},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number'},
                {name:'feeWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number',readOnly:true},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额',type:'number',readOnly:true},
                {name:'invoiceAmount',display: CSIS.Lang.ID_140270||'人民币单价',type:'number',readOnly:true},
                {name:'className',display: CSIS.Lang.ID_101350||'设备名称',type:'string',readOnly:true},
                {name:'supplierName',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true},
                {name:'equipModel',display: CSIS.Lang.ID_125080||'设备型号',type:'string',readOnly:true},
                {name:'cwbtName',display: CSIS.Lang.ID_140240||'入库类型',type:'string',readOnly:true},
                {name:'auditQty',display: CSIS.Lang.ID_140280||'已开票数量',type:'string'},
                {name:'noAuditQty',display: CSIS.Lang.ID_140290||'未开票数量',type:'string'},
                {name:'currencyName',display: CSIS.Lang.ID_107050||'币种名称',type:'string'},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string'},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:60},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number'},
                {name:'auditedFlag',display: CSIS.Lang.ID_138710||'审核标记'},
                {name:'applyConfirmId'},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额'},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {grid:'cwbtCode,ifEst,vesselName,className,materialNo,materialName,cwbtName,activityDate,qty,supplierName,' +
            'currencyName,rate,relatedAmountWithoutTax,taxAmount,cnyFee,invoiceAmount,auditedFlag,ifPaid,remark'
            });

            var vwFmmVrmShipGuideQueryDomain2 = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name: 'feeInvoiceId'},
                {name: 'relatedId'},
                {name: 'vesselCode'},
                {name: 'classNo'},
                {name: 'vesselCode'},
                {name: 'vesselName', display: CSIS.Lang.ID_214470||'船舶', width: 100},
                {name: 'cwbtCode', display: CSIS.Lang.ID_109990||'设备编码', length: 50,width:140},
                {name: 'cwbtName', display: CSIS.Lang.ID_101350||'设备名称', isNull: true, length: {search: 200, edit: 200}, width: 180},
                {name: 'materialNo', display: CSIS.Lang.ID_125080||'设备型号', isNull: true, length: {search: 200, edit: 200}, width: 150},
                {name: 'reportDate', display: CSIS.Lang.ID_126890||'报修日期', isNull: true, type: 'date', format: 'Y-m-d'},
                {name: 'reportPerson', display: CSIS.Lang.ID_140310||'报修人', isNull: true, length: {search: 50, edit: 50}},
                {name: 'supplierCode', display: CSIS.Lang.ID_123830||'承修单位', isNull: true, length: 200},
                {name: 'supplierName', display: CSIS.Lang.ID_123830||'承修单位', width: 250},
                {name: 'activityDate', display: CSIS.Lang.ID_123940||'完工日期', isNull: true, type: 'date', format: 'Y-m-d'},
                {name: 'materialName', display: CSIS.Lang.ID_140320||'是否完工', length: 2,render:strikeRender},
                {name: 'portName', display: CSIS.Lang.ID_111420||'港口', length: 10},
                {name: 'rate', display: CSIS.Lang.ID_140330||'预估费用', type: 'number', regex: /^[0-9]{1,7}(\.[0-9]{1,3})?$/, format: {edit: '0.000'}, length: 11},
                {name: 'auditedFlag', display: CSIS.Lang.ID_115750||'审核状态', length: 10},
                {name: 'faultStatus', display: CSIS.Lang.ID_140340||'故障现状', type: 'text', length: 1000,width:150},
                {name: 'repairContent', display: CSIS.Lang.ID_140350||'修理内容', type: 'text', length: 1000},
                {name: 'relatedName', display: CSIS.Lang.ID_111420||'港口', length: 10},
                {name: 'className', display: CSIS.Lang.ID_140360||'修理类型', length: 10},
                {name: 'companyCode', display: CSIS.Lang.ID_101370||'管理部门', width: 200, readOnly: true, length: 200},
                { name:'vesselCompany', display: CSIS.Lang.ID_110230||'所属公司'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:120},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number',readOnly:true},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额',type:'number',readOnly:true},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {
                grid: 'className,ifEst,vesselName,cwbtCode,activityDate,materialName,relatedName,rate,' +
                'auditedFlag,faultStatus,repairContent,companyCode,cwbtName,materialNo,reportDate,' +
                'reportPerson,supplierName,relatedAmountWithoutTax,taxAmount,cnyFee,ifPaid'
            })


            var vwFmmVrmGridDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'feeInvoiceId'},
                {name:'vesselName',display: CSIS.Lang.ID_107220||'船舶',type:'string',readOnly:true},
                {name:'classNo',display: CSIS.Lang.ID_123840||'修理类别',type:'string',readOnly:true,width:140},
                {name:'className',display: CSIS.Lang.ID_123840||'修理类别',type:'string',readOnly:true,width:60},
                {name:'materialName',display: CSIS.Lang.ID_806409||'送SAP用户',type:'string',readOnly:true,width:60},
                {name:'cwbtCode',display: CSIS.Lang.ID_106660||'申请单号',type:'string',readOnly:true,width:140},
                {name:'portOnlineName',display: CSIS.Lang.ID_123870||'上线港口',type:'string',readOnly:true,width:95},
                {name:'supplierCode',display: CSIS.Lang.ID_123830||'承修单位',type:'string',readOnly:true},
                {name:'supplierName',display:CSIS.Lang.ID_123830||'承修单位',type:'string',readOnly:true,width:200},
                {name:'applyStatus',display: CSIS.Lang.ID_107040||'',type:'string',readOnly:true},
                {name:'applyStatusName',display: CSIS.Lang.ID_107040||'状态',type:'string',readOnly:true},
                {name:'applyDate',display: CSIS.Lang.ID_107040||'申请日期',type:'date',format:'Y-m-d',readOnly:true},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string',readOnly:true},
                {name:'itemNo',display: CSIS.Lang.ID_107040||'项目编号',type:'string',readOnly:true},
                {name:'activityDate',display: CSIS.Lang.ID_238960||'送SAP时间',type:'date',format:'Y-m-d',readOnly:true},
                {name:'faultStatus',display: CSIS.Lang.ID_171140||'是否安全生产费',type:'string',readOnly:true},
                {name:'itemClass',display: CSIS.Lang.ID_107040||'项目类别',type:'string',readOnly:true},
                {name:'classNo',display: CSIS.Lang.ID_107040||'项目类别',type:'string',readOnly:true},
                {name:'repairContent',display: CSIS.Lang.ID_107040||'工程内容',type:'string',readOnly:true,width:140},
                {name:'qty',display: CSIS.Lang.ID_111650||'数量',type:'number'},
                {name:'reportPerson',display: CSIS.Lang.ID_107040||'状态',type:'string'},
                {name:'reportDate',display: CSIS.Lang.ID_123940||'完工日期',type:'date',format:'Y-m-d'},
                {name:'relatedAmount',display: CSIS.Lang.ID_107040||'报价',type:'number',readOnly:true},
                {name:'repairstat',display: CSIS.Lang.ID_107040||'完工标记',type:'string',readOnly:true},
                {name:'auditedFlag',display: CSIS.Lang.ID_107040||'完工标记',type:'string',readOnly:true},
                {name:'cwbtName',display: CSIS.Lang.ID_136460||'工程单号',type:'string',readOnly:true},
                {name:'materialNo',display: CSIS.Lang.ID_107040||'PMS相关计划',type:'string',readOnly:true,width:140},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string'},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:140,readOnly:true},
                {name:'currencyName',display: CSIS.Lang.ID_107510||'币种',width:50},
                {name:'relatedAmountWithoutTax',display:CSIS.Lang.ID_110800||'不含税金额',type:'number'},
                {name:'relatedAmount',display:CSIS.Lang.ID_110770||'含税金额',type:'number'},
                {name:'rate',display:CSIS.Lang.ID_107600||'税率',type:'number'},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'cnyFee',display:CSIS.Lang.ID_112580||'人民币金额',type:'number'},
                {name:'applyConfirmId',display:CSIS.Lang.ID_179950||'内部订单',type:'string'},
                {name:'innerOrderId',display:CSIS.Lang.ID_221670||'开票状态',type:'string'},
                {name:'isSafeprod',display:CSIS.Lang.ID_171140||'是否安全生产费',type:'boolean'},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {grid:'className,ifEst,vesselName,cwbtCode,cwbtName,reportDate,supplierName,currencyName,relatedAmountWithoutTax,' +
                    'taxAmount,relatedAmount,cnyFee,applyConfirmId,materialName,activityDate,innerOrderId,faultStatus,ifPaid',
                orderBy:'completeDate desc'
            });

            var vwFmmMtrPurGridDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'feeInvoiceId'},
                {name:'relatedId'},
                {name:'exchangeRate'},
                {name:'cnyExchangeRate'},
                {name:'className'},
                {name:'vesselCode'},
                {name:'vesselName',display: CSIS.Lang.ID_100060||'船舶名称',type:'string',readOnly:true},
                {name:'classNo',display: CSIS.Lang.ID_140370||'物料类别代码',type:'string',readOnly:true},
                {name:'materialNo',display: CSIS.Lang.ID_140380||'物料编号',type:'string',readOnly:true,width:140},
                {name:'materialInfoId',display: CSIS.Lang.ID_140380||'物料编号',type:'string',readOnly:true,width:140},
                {name:'materialName',display: CSIS.Lang.ID_140390||'物料名称',type:'string',readOnly:true,width:140},
                {name:'activityTypeDetail',display: CSIS.Lang.ID_140400||'采购类型',type:'string',readOnly:true},
                {name:'activityDate',display: CSIS.Lang.ID_140250||'入库日期',type:'date',format:'Y-m-d',readOnly:true},
                {name:'qty',display: CSIS.Lang.ID_140260||'开票数量',type:'number'},
                {name:'supplierCode',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',type:'string',readOnly:true},
                {name:'rate',display: CSIS.Lang.ID_107420||'单价',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_115370||'金额',type:'number'},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number',readOnly:true},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_112580||'人民币金额',type:'number',readOnly:true},
                {name:'invoiceAmount',display: CSIS.Lang.ID_140270||'人民币单价',type:'number',readOnly:true},
                {name:'className',display: CSIS.Lang.ID_140410||'物料分类',type:'string',readOnly:true},
                {name:'supplierName',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true,width:150},
                {name:'model',display: CSIS.Lang.ID_125080||'设备型号',type:'string',readOnly:true},
                {name:'cwbtName',display: CSIS.Lang.ID_140240||'入库类型',type:'string',readOnly:true},
                {name:'ifGroup',display: CSIS.Lang.ID_114730||'客户类型',type:'string',readOnly:true},
                {name:'auditQty',display: CSIS.Lang.ID_140280||'已开票数量',type:'string'},
                {name:'noAuditQty',display: CSIS.Lang.ID_140290||'未开票数量',type:'string'},
                {name:'currencyName',display: CSIS.Lang.ID_107050||'币种名称',type:'string'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:140,readOnly:true},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string'},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率'},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number'},
                {name:'applyConfirmId'},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额'},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {grid:'cwbtCode,ifEst,vesselName,className,materialName,cwbtName,activityDate,supplierName,' +
            'currencyName,rate,relatedAmountWithoutTax,taxAmount,cnyFee,invoiceAmount,materialNo,ifPaid',
                orderBy:'activityDate desc'
            });

            var vwFmmBndPurGridDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'feeInvoiceId'},
                {name:'relatedId'},
                {name:'exchangeRate'},
                {name:'cnyExchangeRate'},
                {name:'className'},
                {name:'vesselCode'},
                {name:'vesselName',display: CSIS.Lang.ID_100060||'船舶名称',type:'string',readOnly:true},
                {name:'classNo',display: CSIS.Lang.ID_806401||'绑垫料类别代码',type:'string',readOnly:true},
                {name:'materialNo',display: CSIS.Lang.ID_806402||'绑垫料编号',type:'string',readOnly:true,width:140},
                {name:'materialInfoId',display: CSIS.Lang.ID_806402||'绑垫料编号',type:'string',readOnly:true,width:140},
                {name:'materialName',display: CSIS.Lang.ID_806403||'绑垫料名称',type:'string',readOnly:true,width:140},
                {name:'activityTypeDetail',display: CSIS.Lang.ID_140400||'采购类型',type:'string',readOnly:true},
                {name:'activityDate',display: CSIS.Lang.ID_140250||'入库日期',type:'date',format:'Y-m-d',readOnly:true},
                {name:'qty',display: CSIS.Lang.ID_140260||'开票数量',type:'number'},
                {name:'supplierCode',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',type:'string',readOnly:true},
                {name:'rate',display: CSIS.Lang.ID_107420||'单价',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_115370||'金额',type:'number'},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number',readOnly:true},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_112580||'人民币金额',type:'number',readOnly:true},
                {name:'invoiceAmount',display: CSIS.Lang.ID_140270||'人民币单价',type:'number',readOnly:true},
                {name:'className',display: CSIS.Lang.ID_806404||'绑垫料分类',type:'string',readOnly:true},
                {name:'supplierName',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true,width:150},
                {name:'model',display: CSIS.Lang.ID_125080||'设备型号',type:'string',readOnly:true},
                {name:'cwbtName',display: CSIS.Lang.ID_140240||'入库类型',type:'string',readOnly:true},
                {name:'ifGroup',display: CSIS.Lang.ID_114730||'客户类型',type:'string',readOnly:true},
                {name:'auditQty',display: CSIS.Lang.ID_140280||'已开票数量',type:'string'},
                {name:'noAuditQty',display: CSIS.Lang.ID_140290||'未开票数量',type:'string'},
                {name:'currencyName',display: CSIS.Lang.ID_107050||'币种名称',type:'string'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:140,readOnly:true},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string'},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率'},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number'},
                {name:'applyConfirmId'},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额'},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {grid:'cwbtCode,ifEst,vesselName,className,materialName,cwbtName,activityDate,supplierName,' +
                    'currencyName,rate,relatedAmountWithoutTax,taxAmount,cnyFee,invoiceAmount,materialNo,ifPaid',
                orderBy:'activityDate desc'
            });

            //add on 220303。用于航海资料
            var vwFmmVdmPurGridDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'feeInvoiceId'},
                {name:'relatedId'},
                {name:'exchangeRate'},
                {name:'cnyExchangeRate'},
                {name:'className'},
                {name:'vesselCode'},
                {name:'vesselName',display: CSIS.Lang.ID_100060||'船舶名称',type:'string',readOnly:true},
                {name:'classNo',display: CSIS.Lang.ID_806405||'航海资料类别代码',type:'string',readOnly:true},
                {name:'materialNo',display: CSIS.Lang.ID_806406||'资料编号',type:'string',readOnly:true,width:140},
                {name:'materialInfoId',display: '绑垫料编号',type:'string',readOnly:true,width:140},
                {name:'materialName',display: CSIS.Lang.ID_806407||'资料名称',type:'string',readOnly:true,width:140},
                {name:'activityTypeDetail',display: CSIS.Lang.ID_140400||'采购类型',type:'string',readOnly:true},
                {name:'activityDate',display: CSIS.Lang.ID_140250||'入库日期',type:'date',format:'Y-m-d',readOnly:true},
                {name:'qty',display: CSIS.Lang.ID_140260||'开票数量',type:'number'},
                {name:'supplierCode',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true},
                {name:'currency',display: CSIS.Lang.ID_107510||'币种',type:'string',readOnly:true},
                {name:'rate',display: CSIS.Lang.ID_107420||'单价',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_115370||'金额',type:'number'},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_110800||'不含税金额',type:'number',readOnly:true},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number',readOnly:true},
                {name:'relatedAmount',display: CSIS.Lang.ID_112580||'人民币金额',type:'number',readOnly:true},
                {name:'invoiceAmount',display: CSIS.Lang.ID_140270||'人民币单价',type:'number',readOnly:true},
                {name:'className',display: CSIS.Lang.ID_806408||'资料分类',type:'string',readOnly:true},
                {name:'supplierName',display: CSIS.Lang.ID_107250||'供应商',type:'string',readOnly:true,width:150},
                {name:'model',display: CSIS.Lang.ID_125080||'设备型号',type:'string',readOnly:true},
                {name:'cwbtName',display: CSIS.Lang.ID_140240||'入库类型',type:'string',readOnly:true},
                {name:'ifGroup',display: CSIS.Lang.ID_114730||'客户类型',type:'string',readOnly:true},
                {name:'auditQty',display: CSIS.Lang.ID_140280||'已开票数量',type:'string'},
                {name:'noAuditQty',display: CSIS.Lang.ID_140290||'未开票数量',type:'string'},
                {name:'currencyName',display: CSIS.Lang.ID_107050||'币种名称',type:'string'},
                {name:'cwbtCode',display: CSIS.Lang.ID_139620||'流水单号',type:'string',width:140,readOnly:true},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string'},
                {name:'taxRateName',display: CSIS.Lang.ID_107600||'税率'},
                {name:'taxAmount',display: CSIS.Lang.ID_107610||'税金',type:'number'},
                {name:'applyConfirmId'},
                {name:'cnyFee',display: CSIS.Lang.ID_112580||'人民币金额'},
                {name: 'ifEst', display: CSIS.Lang.ID_140300||'是否已送预估',type:'boolean'},
                {name: 'ifPaid', display: CSIS.Lang.ID_138420||'发票是否来齐', type: 'boolean'}
            ], {grid:'cwbtCode,ifEst,vesselName,className,materialName,supplierName,' +
            'currencyName,rate,relatedAmountWithoutTax,taxAmount,cnyFee,invoiceAmount,materialNo,ifPaid',
                orderBy:'activityDate desc'
            });


            //行切换事件，在本行选择后触??支持上下键选择记录
            var perRecode = 0;
            page.getGridBox().addListener('rowSelected', function(src, event, record, index){
                commonListener(record);
                if(isChange){
                    changeGrid(record);
                }
            })

            var type = "";
            function changeGrid(record){
                if(true){//先走新的逻辑，原来的逻辑先buyong
                    changeGrid2(record)
                    return
                }
            }

            var loadNum = 0;   //加载次数
            function changeGrid2(record){
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                if(invoiceSort=='FY01' || invoiceSort=='FY02' || invoiceSort=='FY61'|| invoiceSort=='FY62'|| invoiceSort=='FY63' || invoiceSort=='FY05'
                        || invoiceSort=='FY64' || invoiceSort=='FY06'|| invoiceSort=='FY69' || invoiceSort=='FY67'
                        || invoiceSort=='FY77'|| invoiceSort=='FY78' || invoiceSort=='FY98' || invoiceSort == 'FY97'||invoiceSortDetail== 'FY56001'||invoiceSortDetail== 'FY56002'||invoiceSortDetail== 'FY56003') {
                    if(invoiceSortDetail == 'FY01003'||invoiceSortDetail == 'FY01004'||invoiceSortDetail== 'FY64001'||
                            invoiceSortDetail == 'FY02003'||invoiceSortDetail == 'FY02004' ||invoiceSort== 'FY63'||invoiceSortDetail== 'FY56001'||invoiceSortDetail== 'FY56002'||invoiceSortDetail== 'FY56003'){
                        if(perRecode != 1){
                            grid.changeDomain(vwFmmSpsPurGridDomain,vwFmmSpsPurGridDomain.getConfig("grid"));
                            curDomain = vwFmmSpsPurGridDomain;
                            perRecode = 1;
                            type = "BJ";
                        }
                    }else if (companyCode.startWith('65')&&(invoiceSortDetail == 'FY64005' || invoiceSortDetail == 'FY64006')) {
                        if (invoiceSortDetail == 'FY64005') {
                            grid.changeDomain(vwFmmSpsPurGridDomain,vwFmmSpsPurGridDomain.getConfig("grid"));
                            curDomain = vwFmmSpsPurGridDomain;
                            perRecode = 1;
                            type = "BJ";
                        } else if (invoiceSortDetail == 'FY64006') {
                            grid.changeDomain(vwFmmMtrPurGridDomain,vwFmmMtrPurGridDomain.getConfig("grid"));
                            curDomain = vwFmmMtrPurGridDomain;
                            perRecode = 4;
                            type = "WL";
                        }
                    }else if((companyCode.startWith('66')||companyCode.startWith('9101'))&&(invoiceSort == 'FY01'||invoiceSort == 'FY61'||invoiceSort == 'FY62'||invoiceSort == 'FY05'||
                            invoiceSort == 'FY64'||invoiceSort == 'FY06'||invoiceSort == 'FY69'||invoiceSort == 'FY67'||invoiceSort == 'FY77'||invoiceSort == 'FY78'||invoiceSort == 'FY79'||invoiceSortDetail== 'FY56002'||invoiceSortDetail== 'FY56003')){
                        if(perRecode !=3){
                            grid.changeDomain(vwFmmVrmGridDomain,vwFmmVrmGridDomain.getConfig("grid"));
                            curDomain = vwFmmVrmGridDomain;
                            perRecode = 3;
                            type = "XL";
                        }
                    }else if(invoiceSortDetail == 'FY01002' || invoiceSortDetail == 'FY01005'
                            || invoiceSortDetail == 'FY01007'|| invoiceSort == 'FY62'|| invoiceSort == 'FY67'|| invoiceSort == 'FY69'
                            || invoiceSort == 'FY97'){
                        if(perRecode != 2){
                            grid.changeDomain(vwFmmVrmShipGuideQueryDomain2,vwFmmVrmShipGuideQueryDomain2.getConfig("grid"));
                            curDomain = vwFmmVrmShipGuideQueryDomain2;
                            perRecode = 2;
                            type = "TD";
                        }
                    } else {
                        if(perRecode !=3){
                            grid.changeDomain(vwFmmVrmGridDomain,vwFmmVrmGridDomain.getConfig("grid"));
                            curDomain = vwFmmVrmGridDomain;
                            perRecode = 3;
                            type = "XL";
                        }
                    }
                }else if(invoiceSort == 'FY04' || (invoiceSort == 'FY28' && companyCode.startWith('65')) || invoiceSort == 'FY34' || invoiceSort == 'FY33'|| invoiceSort == 'FY65'|| invoiceSort == 'FY66' || invoiceSort == 'FY58'){
                    if(perRecode!=4){
                        grid.changeDomain(vwFmmMtrPurGridDomain,vwFmmMtrPurGridDomain.getConfig("grid"));
                        curDomain = vwFmmMtrPurGridDomain;
                        perRecode = 4;
                        type = "WL";
                    }
                }else if(invoiceSort == 'FYCL' || invoiceSort == 'FYHW' || invoiceSort == 'FYHF'){ //海特绑垫料材料和货物费用
                    grid.changeDomain(vwFmmBndPurGridDomain,vwFmmBndPurGridDomain.getConfig("grid"));
                    curDomain = vwFmmBndPurGridDomain;
                    perRecode = 5;
                    type = "BND";
                }else if(invoiceSort == 'FY70'){//航海资料
                    grid.changeDomain(vwFmmVdmPurGridDomain,vwFmmVdmPurGridDomain.getConfig("grid"));
                    curDomain = vwFmmVdmPurGridDomain;
                    perRecode = 5;
                    type = "VDM";
                }else if(invoiceSort == 'FYRG'){ //海特绑垫料人工费用
                    grid.changeDomain(vwFmmBndPurGridDomain,vwFmmBndPurGridDomain.getConfig("grid"));
                    curDomain = vwFmmBndPurGridDomain;
                    perRecode = 5;
                    type = "BNDRG";
                } else{
                    curDomain.getDataSource().loadDataset({feeInvoiceId:"XXXXXXX",type:type,limit:1000});
                    return;
                }

                //从订单那边过来数据
                if(tempRecordLists.length>0)billNoFlag = true
                if(!billNoFlag&&isCreate==false)//如果是新增的话，不要从上面加载
                    curDomain.getDataSource().loadDataset({feeInvoiceId:record.feeInvoiceId,type:type,limit:1000});
                if(loadNum==0){
                    if(type == 'WL'||type == 'BJ'){
                        curDomain.getDataSource().addListener('load', function (store, record, success, etops) {
                            if (record.length == 0) {
                                curDomain.getDataSource().clearRecords();
                            } else {
                                // relatedAmountWithoutTax,taxAmount,cnyFee
                                var relatedAmountWithoutTaxSum = 0;  //不含税金额总和
                                var taxAmountSum = 0;   //税金总和
                                var cnyFeeSum = 0 ;   //人民币金额总和
                                Ext.each(record, function (v) {
                                    relatedAmountWithoutTaxSum += v.data.relatedAmountWithoutTax == '' ? 0 : v.data.relatedAmountWithoutTax
                                    taxAmountSum += v.data.taxAmount == '' ? 0 : v.data.taxAmount
                                    cnyFeeSum += v.data.cnyFee == '' ? 0 : v.data.cnyFee
                                });
                                curDomain.getDataSource().newRecord({currencyName: CSIS.Lang.ID_140420||'合计：', relatedAmountWithoutTax: Number(relatedAmountWithoutTaxSum).toFixed(2), taxAmount: Number(taxAmountSum).toFixed(2),
                                    cnyFee: Number(cnyFeeSum).toFixed(2)});
                                calOperationCheckAmount();
                            }
                            loadNum++;
                        });
                    }
                }

            }

            page.getEditBox().getEditArea().getUI().addListener('beforetabchange', function(tabPanel,newCard, oldCard) {
                var  invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                if(newCard.title==(CSIS.Lang.ID_139800||'订单项')) {
                    if (!('FY01004FY16002'.indexOf(invoiceSortDetail) >=0||'FY04'==invoiceSortDetail.substring(0,4))||invoiceSortDetail == ""||!daYuanFlag) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_140430||"除大远备件物料油漆及劳保费可用！");
                        return false;
                    }else{
                        page.getEditBox().getExtField('equipUse1').show()
                        page.getEditBox().getExtField('equipUse2').show()
                        page.getEditBox().getExtField('equipUse3').show()
                        page.getEditBox().getExtField('equipUse4').show()
                        if(invoiceSortDetail=='FY01004') {
                            if(!isCreate&&currentRecord.equipUse)
                                page.getEditBox().getExtField('equipUse1').setValue(currentRecord.equipUse)
                            page.getEditBox().getExtField('equipUse2').hide()
                            page.getEditBox().getExtField('equipUse3').hide()
                            page.getEditBox().getExtField('equipUse4').hide()}
                        else if(invoiceSortDetail=='FY04001') {
                            if(!isCreate&&currentRecord.equipUse)
                                page.getEditBox().getExtField('equipUse4').setValue(currentRecord.equipUse)
                            page.getEditBox().getExtField('equipUse1').hide()
                            page.getEditBox().getExtField('equipUse2').hide()
                            page.getEditBox().getExtField('equipUse3').hide()
                        }
                        else if(invoiceSortDetail.substring(0,4)=='FY04') {
                            if(!isCreate&&currentRecord.equipUse)
                                page.getEditBox().getExtField('equipUse3').setValue(currentRecord.equipUse)
                            page.getEditBox().getExtField('equipUse1').hide()
                            page.getEditBox().getExtField('equipUse2').hide()
                            page.getEditBox().getExtField('equipUse4').hide()
                        }
                        else {
                            if(!isCreate&&currentRecord.equipUse)
                                page.getEditBox().getExtField('equipUse2').setValue(currentRecord.equipUse)
                            page.getEditBox().getExtField('equipUse1').hide()
                            page.getEditBox().getExtField('equipUse3').hide()
                            page.getEditBox().getExtField('equipUse4').hide()
                        }
                    }
                }
            });

            var isChange = false;
            //控制主表tab页才能使用工具条
            page.getEditBox().getEditArea().getUI().addListener('tabchange', function(tabPanel, newCard, oldCard) {
                if(newCard.title == (CSIS.Lang.ID_140030||'关联信息')){
                    isChange = true;
                    changeGrid(currentRecord);
                }else{
                    isChange = false;
                }
                if(newCard.title == (CSIS.Lang.ID_140030||'关联信息') || newCard.title == (CSIS.Lang.ID_139790||'付款状态')||newCard.title ==(CSIS.Lang.ID_139800||'订单项')){
                    page.getToolbarBox().getUI().hide();
                    btnNegReversal_sub.hide();
                    btnPaymentNotice_sub.hide();
                    btnOperation_sub.hide();
                }else{
                    page.getToolbarBox().getUI().show();
                    btnNegReversal_sub.show();
                    btnPaymentNotice_sub.show();
                    btnOperation_sub.show();
                }
                if(newCard.title == '附件'){
                    if(currentRecord!=null){
                        if(!isEmpty(currentRecord.paymentNoticeId)) attachmentDomain.getDataSource().loadDataset({referenceId: currentRecord.paymentNoticeId});
                        else attachmentDomain.getDataSource().loadDataset({referenceIdOne: currentRecord.feeInvoiceId});
                    }
                }
                if(newCard.title==(CSIS.Lang.ID_139800||'订单项')){
                    page.getEditBox().getExtField('equipUse').setValue()
                    page.getEditBox().getExtField('invoiceSortDy').setDisabled(true)
                    page.getEditBox().getExtField('invoiceSortDetailDy').setDisabled(true)
                    page.getEditBox().getExtField('invoiceSortDy').setValue(page.getEditBox().getExtField('invoiceSort').rawValue)
                    page.getEditBox().getExtField('invoiceSortDetailDy').setValue(page.getEditBox().getExtField('invoiceSortDetail').rawValue)
                }
                if(newCard.title =='海图账单明细'&&companyCode.startWith('0802')){
                    console.info(currentRecord.feeInvoiceId)
                    fmmFeeInvoiceSeachatDtlDomain.getDataSource().loadDataset({feeInvoiceId:currentRecord.feeInvoiceId})
                }
            })

            function focusFieldOnCreate(){
                var invoiceNo = page.getEditBox().getValue('invoiceNo');
                if(!invoiceNo){
                    page.getEditBox().getExtField('invoiceSort').focus();
                    return;
                }
                C.ajax.callAction('focusField','feeInvoice',{invoiceNo:invoiceNo},function(action,domainName,resp){
                    if(resp && resp.success){
                        if(resp.msg == '1'){//表示已经完成本张发票
                            page.getEditBox().getExtField('invoiceSort').focus();
                        }else{
                            page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                        }
                    }
                });
            }

            //设置负冲销、生成付款单、关联信息三个按钮的状态。仅用于点击按钮时触发，已包括权限控制
            function set3ButtonStatus(status){
                if(status){
                    setButtonStatus('negRev',true);
                    setButtonStatus('payNoti',true);
                    setButtonStatus('opera',true);
                }else{
                    setButtonStatus('negRev',false);
                    setButtonStatus('payNoti',false);
                    setButtonStatus('opera',false);
                }
            }


            var isCreate = false;
            var isEdit =  false;
            var doBtnCreateFlag;
            var rollbackUpdateFlag=false;
            var listenerFlag = 0;
            //新增时候为某些字段赋值
            var _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow,signNo,taxCheckState';
            function doBtnCreate(){
                salesName = '';
                purchaserName = '';
                page.getEditBox().clearBox();
                if(companyCode.startWith("0200")){
                    _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,billNo,taxCheckState';
                }
                if(companyCode.startWith("68")){
                    _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow,dockSelfPolishingQty,dockSelfPolishingAmount,dockOtherQty,dockOtherAmount,maintainPrimerQty,maintainPrimerAmount,maintainOtherQty,maintainOtherAmount,dockOrMaintainTotalAmount,taxCheckState';
                }
                if(companyCode.startWith("6600"))_exception+=",isAdvanceFee";
                if(companyCode.startWith("08011100"))_exception+=",isAdvanceFee";
                if(youlunFlag){  //每次点击新增需要刷新字段
                    _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow,signNo,taxCheckState,isAdvanceFee,billNo';
                    if(currentRecord){
                        var invoiceSort = currentRecord.invoiceSort;
                        var invoiceSortDetail = currentRecord.invoiceSortDetail;
                        var srcOrderType = currentRecord.srcOrderType;
                        if(invoiceSort!="FY06"&&invoiceSort!="ZCF"){  _exception+=",srcOrderType"; }
                        if(!daYuanFlag){
                            if( (invoiceSort=='FY01'&&(invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'))||(invoiceSort=='FY06'&&(srcOrderType!='1'&&srcOrderType!='2'&&srcOrderType!='3'&&srcOrderType!='13'))){
                                _exception+=",invoiceNo,invoiceDate,invoiceCode";  }
                            if(invoiceSort=='ZCF')setBoxReadOnlyEx(page.getEditBox(),false,'billNo'); else setBoxReadOnlyEx(page.getEditBox(),true,'billNo');
                        }
                    }
                }
                page.getEditBox().setBoxReadOnly(false,_exception);
                if (currentId == "ff8080815a35be42015a35cb71860001") { //通导模块
                    page.getEditBox().getExtField("invoiceSort").setComboValue("FY67",CSIS.Lang.ID_139490||"通导修备费");
                }
                if(!page.getGridBox().getSelectedRecord())currentRecord = null;
                //前提是否是新增标志，setCreateDefaultValue里的setComboGrid方法如果当前选中行不是新增的话，新增发票会用当前选中行的状态覆盖新增状态
                isCreate = true;
                isEdit = false;
                setCreateDefaultValue();
                page.getEditBox().getExtField("invoiceStatus").setComboValue("1",CSIS.Lang.ID_115590||"新增");
                focusFieldOnCreate();
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue()
                if (invoiceSort == 'FY33') {
                    page.getEditBox().setReadOnly('quantity', false);
                    page.getEditBox().setReadOnly('portCode', false);
                }
                if(companyCode.startWith("08011100")){
                    if(invoiceSortDetail=='FY64002'||invoiceSortDetail=='FY49022'||invoiceSortDetail=='FY49021'||invoiceSortDetail=='FY64011'){
                        page.getEditBox().setReadOnly('isAdvanceFee', false);
                    }else{
                        page.getEditBox().setReadOnly('isAdvanceFee', true);
                    }
                    var falg = true;
                    if(!isEmpty(invoiceSortDetail)){
                        C.syncRequest.callAction("list","freight",{freightCode:invoiceSortDetail},
                            function (actionName, domainName, resp) {
                                var result = resp.rows
                                if(!isEmpty(result) && result.length>0){
                                    var row = result[0];
                                    if(row.isNonOperating != 1){
                                        falg = false;
                                    }
                                }
                        });
                    }
                    if(!falg){
                        page.getEditBox().setReadOnly('portCode', false);
                    }else{
                        page.getEditBox().getExtField('portCode').setValue('')
                        page.getEditBox().setReadOnly('portCode', true);
                    }
                }
                if(youlunFlag)setFreight();
                //先把原关联信息页中的记录给清除掉
                var records = curDomain.getDataSource().getGridAllRecords();
                curDomain.getDataSource().deleteRecords(records);
                curDomain.getDataSource().clearRecords()
                doBtnCreateFlag = true;
                listenerFlag = 0;
                isNeedChange = true;
                set3ButtonStatus(false);

                if (bndFlag) {
                    page.getEditBox().setReadOnly('portCode', false);
                    page.getEditBox().setReadOnly('voyageNo', true);
                }
            }
            page.getToolbarBox().addListener('create',doBtnCreate);

            function doBtnEdit(){
                salesName = '';
                purchaserName = '';
                var invoiceSortDetail=   page.getEditBox().getExtField('invoiceSortDetail').getComboValue().display;
                if( ((!daYuanFlag&&!companyCode.startWith("1331")&&!companyCode.startWith("6207")&&!companyCode.startWith("0811"))&&(CSIS.Lang.ID_140440||"油公司检验费")==invoiceSortDetail)&&IsYYfee==false){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"针对油轮公司费用科目为油公司检验费的数据，只有辛钢、张欣、王洪波可以操作！");
                    return false;
                }
                var eb = page.getEditBox();
                setComboGrid(eb);
                setFieldDisabledCommon();
                if(companyCode.startWith("68")){
                    _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow';
                    if(currentRecord&&currentRecord.invoiceSort=="FY72"){
                        _exception += ",dockSelfPolishingQty,dockSelfPolishingAmount,dockOtherQty,dockOtherAmount,dockOrMaintainTotalAmount"
                    }else if(currentRecord&&currentRecord.invoiceSort=="FY76"){
                        _exception += ",maintainPrimerQty,maintainPrimerAmount,maintainOtherQty,maintainOtherAmount,dockOrMaintainTotalAmount"
                    }else{
                        _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow';
                    }
                    page.getEditBox().setBoxReadOnly(false,_exception);
                }else if(youlunFlag){
                    if(currentRecord){
                        var invoiceSort = currentRecord.invoiceSort;
                        var invoiceSortDetail = currentRecord.invoiceSortDetail;
                        var srcOrderType = currentRecord.srcOrderType;
                        _exception = 'inputUser,inputDate,orderNo,projectName,unit,quantity,portCode,feeFlow,signNo,taxCheckState,billNo,isAdvanceFee';
                        if(invoiceSort!="FY06"&&invoiceSort!="ZCF"){_exception+=",srcOrderType"; }
                        if(!daYuanFlag){
                            if( (invoiceSort=='FY01'&&(invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'))||invoiceSort=='FY06'){
                                _exception+=",invoiceNo,invoiceDate,invoiceCode";
                            } } }
                    page.getEditBox().setBoxReadOnly(false,_exception);
                    var innerOrder = page.getEditBox().getExtField('innerOrder').getValue()
                    if(!isEmpty(innerOrder))page.getEditBox().setReadOnly('occurTimeFrom', true);
                    else page.getEditBox().setReadOnly('occurTimeFrom', false);
                    if(!isEmpty(invoiceSort)&&invoiceSort=='FY06'){
                        if(srcOrderType=='1'||srcOrderType=='2'||srcOrderType=='3'||srcOrderType=='13')setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                        else setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode'); }
                    if(invoiceSort=='ZCF')setBoxReadOnlyEx(page.getEditBox(),false,'billNo'); else setBoxReadOnlyEx(page.getEditBox(),true,'billNo');
                    if(companyCode.substring(0,4)=='0811'||companyCode.substring(0,4)=='1331') setBoxReadOnlyEx(page.getEditBox(),false,'invoiceNo,invoiceDate,invoiceCode')
                }else{
                    if(companyCode.startWith("6600")){if(invoiceSortDetail!='FY61001'){_exception+=",isAdvanceFee";}}
                    page.getEditBox().setBoxReadOnly(false,_exception);
                    var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue();
                    var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue();
                    if(companyCode.startWith("08011100")){
                        if(invoiceSortDetail=='FY64002'||invoiceSortDetail=='FY49022'||invoiceSortDetail=='FY49021'||invoiceSortDetail=='FY64011'){
                            page.getEditBox().setReadOnly('isAdvanceFee', false);
                        }else{
                            page.getEditBox().setReadOnly('isAdvanceFee', true);
                        }
                        var falg = true;
                        if(!isEmpty(invoiceSortDetail)){
                            C.syncRequest.callAction("list","freight",{freightCode:invoiceSortDetail},
                                function (actionName, domainName, resp) {
                                    var result = resp.rows
                                    if(!isEmpty(result) && result.length>0){
                                        var row = result[0];
                                        if(row.isNonOperating != 1){
                                            falg = false;
                                        }
                                    }
                            });
                        }
                        if(!falg){
                            page.getEditBox().setReadOnly('portCode', false);
                        }else{
                            page.getEditBox().getExtField('portCode').setValue('')
                            page.getEditBox().setReadOnly('portCode', true);
                        }
                    }
                }
                var invoiceSort = page.getEditBox().getExtField('invoiceSort').getValue()
                var invoiceSortDetailValue = page.getEditBox().getExtField('invoiceSortDetail').getComboValue().value;
                if (invoiceSort == 'FY33') {
                    page.getEditBox().setReadOnly('quantity', false);
                    page.getEditBox().setReadOnly('portCode', false);
                }
                if (currentRecord.taxCheckState == '0') {
                    setBoxReadOnlyEx(page.getEditBox(),true,"amount,taxAmount,amountWithoutTax,invoiceCode,invoiceDate,currency,ifCanUseTax,taxRate");
                }
                if(youlunFlag){
                    if(invoiceSort == 'FYR1'||(invoiceSort == 'FY69'&&( invoiceSortDetailValue=='FY69004'||invoiceSortDetailValue=='FY69005')) ){
                        page.getEditBox().setReadOnly('portCode', false);
                        page.getEditBox().setReadOnly('voyageNo', false);
                    }else{
                        page.getEditBox().getExtField('portCode').setValue('');  page.getEditBox().setReadOnly('portCode', true);
                        page.getEditBox().getExtField('voyageNo').setValue(''); page.getEditBox().setReadOnly('voyageNo', true);
                    }
                    var isFreight =  page.getEditBox().getValue('isFreight');
                    if(isFreight)setBoxReadOnlyEx(page.getEditBox(), true, 'miscAmount,remark');
                    else setBoxReadOnlyEx(page.getEditBox(), false, 'remark,miscAmount');
                }
                isCreate = false; isEdit = true; doBtnCreateFlag = false; listenerFlag = 0;isNeedChange = true;
                set3ButtonStatus(false);
                var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                if(!isEmpty(vesselCode)){
                    if(permissionMap.containsKey('scanBtn'))scanBtn.setDisabled(false);
                }
                if (bndFlag) {
                    if (isEmpty(page.getEditBox().getExtField("innerOrder").getValue())) {
                        page.getEditBox().setReadOnly('portCode', false);
                    } else {
                        page.getEditBox().setReadOnly('portCode', true);
                    }
                    page.getEditBox().setReadOnly('voyageNo', true);
                }
                //油运的退回提单人只允许编辑币种，税金，汇率，税率，开票单位
                if(youlunFlag && currentRecord && currentRecord.isDoubt=="1"){
                    page.getEditBox().setBoxReadOnly(true)
                    page.getEditBox().getExtField("taxRate").setDisabled(false);
                    page.getEditBox().getExtField("taxAmount").setDisabled(false);
                    setBoxReadOnlyEx(page.getEditBox(),false,"currency,taxAmount,taxRate,ifCanUseTax,payee");
                }
            }
            page.getToolbarBox().addListener('edit',doBtnEdit);

            page.getToolbarBox().addListener('beforeSave',function(self, comp, eventName, state){
                page.getEditBox().setValue('inputUser',userName);
                var dtlAmount = page.getEditBox().getExtField('dtlAmount').getValue()
                var miscAmount = page.getEditBox().getExtField('miscAmount').getValue()
                var innerOrder = page.getEditBox().getExtField('innerOrder').getValue()
                var invoiceSortValue = page.getEditBox().getExtField('invoiceSort').getComboValue().value;
                var payeeCode1 = page.getEditBox().getExtField('payee').getComboValue().value
                var payeeName1 = page.getEditBox().getExtField('payee').getComboValue().display
                var payeeName2 = payeeName1.replace(/'/g,"''");

                var invoiceNo = page.getEditBox().getExtField('invoiceNo').getValue();
                var invoiceCode = page.getEditBox().getExtField('invoiceCode').getValue();
                var invoiceDate = page.getEditBox().getExtField('invoiceDate').getValue();
                var invoiceCheckCode = page.getEditBox().getExtField('invoiceCheckCode').getValue();
                var amountWithoutTax = page.getEditBox().getExtField('amountWithoutTax').getValue();
                // var ifCanUseTax=page.getEditBox().getExtField('ifCanUseTax').getValue();
                // var currency=page.getEditBox().getExtField('currency').getValue();
                // if(companyCode.startWith("1331")){   //1331公司保存之前效验发票合规则查验
                //     debugger
                //     if(currency=='CNY' && (ifCanUseTax==6||ifCanUseTax==7)){
                //         var text="";
                //         C.syncRequest.callAction("beforeSave", "feeInvoice", {
                //             invoiceNo:invoiceNo,
                //             invoiceCode:invoiceCode,
                //             invoiceDate:invoiceDate,
                //             invoiceCheckCode:invoiceCheckCode,
                //             amountWithoutTax:amountWithoutTax,
                //         }, function (action, domain, rsc) {
                //             if (rsc.success) {
                //             } else {
                //                 text=rsc.msg;
                //             }
                //         });
                //         if(text!=null||text!=""){
                //             Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',text)
                //             return false;
                //         }
                //     }
                // }

                //特运只可单独进行订单录入
                if(companyCode.startWith("65")&&isEmpty(innerOrder)&&(innerOrder.indexOf(',') != -1)){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"多订单号不能同时保存，需拆分录入！")
                    return false;
                }

                //特运的备件、物料、修理(除检验外)录入发票订单号必填，除运费和抵扣发票外
                if(companyCode&&companyCode.startWith("65")&&isEmpty(innerOrder)&&!(Number(dtlAmount)==Number(miscAmount)||Number(dtlAmount)<0)&&
                    (/*bndFlag == true||*/invoiceSortValue=="FY63"||invoiceSortValue=="FY04"||invoiceSortValue == 'FY64'||invoiceSortValue == 'FY61'||invoiceSortValue == 'FY62'||invoiceSortValue == 'FY67')){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号！")
                    return false;
                }
                var billNo = page.getEditBox().getValue('billNo');
                if(companyCode&&companyCode.startWith("66")&&isEmpty(billNo)&&(invoiceSortValue=="FY56")){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"内部订单号不能为空，请填写内部订单号！")
                    return false
                }
                if (bndFlag) {
                    var director = page.getEditBox().getExtField('director').getValue();
                    var voyageNo = page.getEditBox().getExtField('voyageNo').getValue();
                    var portCode = page.getEditBox().getExtField('portCode').getValue();
                    if (isEmpty(director) || isEmpty(voyageNo) || isEmpty(portCode)) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"绑垫料费用主管、港口、航次不能为空！")
                        return false;
                    }
                }

                if(payeeCode1!=null && payeeName1!=null){
                    var checkedPayee = true;
                    C.syncRequest.callAction('list', 'customerGridVo', {_extend: " and customerCode='"+payeeCode1+"' and customerName='" + payeeName2 + "' and active = '1' "},
                            function (action, domainName, resp) {
                                if(resp && resp.rows && resp.rows.length>0){
                                    checkedPayee = false
                                }
                            });
                    if(checkedPayee){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_237580||"开票单位不是有效的供应商！")
                        return false
                    }
                }
                if(rollbackUpdateFlag){
                    var checkCurrencyFlag = true;
                    var currency = page.getEditBox().getValue('currency');
                    C.syncRequest.callAction('getFeePayCurrency', 'feePaymentNotice',{paymentNoticeId:currentRecord.paymentNoticeId,currency:currency}, function (actionName, domainName, resp) {
                        checkCurrencyFlag = resp.success;
                    });
                    if(!checkCurrencyFlag){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"该付款单存在多张发票,币种需保持一致");
                        return false;
                    }
                }
                var remark = page.getEditBox().getExtField('remark').getValue()
                if(companyCode.startWith("02") && payeeCode1=="WKQT99" && !remark){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_237590||"其他供应商需要在“备注”填写收款人名称！")
                    return false
                }
                var manager="";
                C.syncRequest.callAction('getVesselManager', 'applyMainMtrVo',{vesselCode:page.getEditBox().getExtField("vesselCode").getValue()}, function (actionName, domainName, resp) {
                    manager=resp.msg;
                });
                var enquireMainApplyDate = page.getEditBox().getExtField("occurTimeFrom").getValue()
                if(manager=="63000000" && isEmpty(enquireMainApplyDate)){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"完工日期不能为空！")
                    return false
                }

                if(companyCode.startWith("91") && isEmpty(enquireMainApplyDate) && (invoiceSortValue=="FY62" || invoiceSortValue=="FY67"||invoiceSortValue=="FY61") ){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"完工日期不能为空！")
                    return false
                }

                if(isEmpty(enquireMainApplyDate)){
                    enquireMainApplyDate = new Date()
                }
                var payerCode = page.getEditBox().getExtField("payer").getComboValue().value
                var payerName = page.getEditBox().getExtField("payer").getComboValue().display
                var validatePayerCode = "";
                var validatePayerName = "";
                var ifCanUseTax = page.getEditBox().getValue('ifCanUseTax');
                //检查本体币是否CNY 本体币不是CNY且ifCanUseTax增值税专用发票1和电子发票（值税专用发票）6
                //境外公司的税率、税金的值不能大于0。payerCodeBodyCurrency!= "CNY"
                if(payerCode && (ifCanUseTax == '1' || ifCanUseTax == '6')){
                    var payerCodeBodyCurrency = "";
                    C.syncRequest.callAction('list','office',{officeCode:payerCode} ,
                        function (action, domainName, resp) {
                            if (resp.total > 0) {
                                payerCodeBodyCurrency = resp.rows[0].homeCurrency;
                            }
                        }
                    )
                    if(payerCodeBodyCurrency && payerCodeBodyCurrency != "CNY"){
                        var taxRate = page.getEditBox().getValue('taxRate') != '其他'?(page.getEditBox().getValue('taxRate')?Number(page.getEditBox().getValue('taxRate')):0):0;
                        var taxAmount = page.getEditBox().getValue('dtlTaxAmount')?Number(page.getEditBox().getValue('dtlTaxAmount')):0;
                        if (taxRate>0||taxAmount>0){
                            Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"境外公司的税率、税金值不能大于0！")
                            return false
                        }
                    }
                }

                //判断付款单位+发票号是否存在，存在给出提示
                var invoiceNo = page.getEditBox().getExtField("invoiceNo").getValue();
                var invoiceCode = page.getEditBox().getExtField("invoiceCode").getValue();
                var invoiceDate = page.getEditBox().getExtField("invoiceDate").getValue();
                var count = 0;
                var countSy = 0; //散运(在校验发票号+付款单位基础上再)添加校验 发票号与开票单位
                if(doBtnCreateFlag==true&&!isEmpty(invoiceNo)){
                    if(payerCode.indexOf("68") == 0 &&  !isEmpty(innerOrder) && (invoiceSortValue == 'FY04'
                            || invoiceSortValue == 'FY62'|| invoiceSortValue == 'FY63'|| invoiceSortValue == 'FY66'|| invoiceSortValue == 'FY72'
                            || invoiceSortValue == 'FY73'|| invoiceSortValue == 'FY74'|| invoiceSortValue == 'FY75'|| invoiceSortValue == 'FY76')){
                        C.syncRequest.callAction('list', 'feeInvoice', {
                                    _extend: " and innerOrder = '"+innerOrder+"' and payer='"+payerCode+"' and invoiceNo='" + invoiceNo + "'"
                                },
                                function (action, domainName, resp) {
                                    count = resp.rows.length;
                                });
                    }else{
                        var countStr = " and payer='"+payerCode+"' and invoiceNo='" + invoiceNo + "'";
                        if(youlunFlag){ countStr+=" and isStrike!='1'";  }
                        C.syncRequest.callAction('list', 'feeInvoice', {_extend:countStr },
                                function (action, domainName, resp) {
                                    count = resp.rows.length;
                                });
                        if(companyCode && companyCode.substring(0,2)=="66"){
                            var extendSql = " and invoiceNo = '" + invoiceNo + "' and payee = '"+payeeCode1+"' "
                            C.syncRequest.callAction('list', 'feeInvoice', {_extend: extendSql},
                                    function (action, domainName, resp) {
                                        countSy = resp.rows.length;
                                    });
                        }
                    }
                }else if(doBtnCreateFlag ==false&&!isEmpty(invoiceNo)){
                    var feeInvoiceId = currentRecord.feeInvoiceId;
                    if(payerCode.indexOf("68") == 0 &&  !isEmpty(innerOrder) && (invoiceSortValue == 'FY04'
                            || invoiceSortValue == 'FY62'|| invoiceSortValue == 'FY63'|| invoiceSortValue == 'FY66'|| invoiceSortValue == 'FY72'
                            || invoiceSortValue == 'FY73'|| invoiceSortValue == 'FY74'|| invoiceSortValue == 'FY75'|| invoiceSortValue == 'FY76')){
                        C.syncRequest.callAction('list', 'feeInvoice', {
                                    _extend: " and innerOrder = '"+innerOrder+"' and payer='"+payerCode+"' and invoiceNo='" + invoiceNo + "' and feeInvoiceId != '" + feeInvoiceId + "' "
                                },
                                function (action, domainName, resp) {
                                    count = resp.rows.length;
                                });
                    }else if(youlunFlag){
                        var countStr = " and payee='"+payeeCode1+"' and invoiceNo='" + invoiceNo + "' and feeInvoiceId != '" + feeInvoiceId + "' ";
                        countStr+=" and isStrike!='1'";
                        C.syncRequest.callAction('list', 'feeInvoice', {_extend:countStr },function (action, domainName, resp) {
                            count = resp.rows.length; });
                    }else{
                        var countStr = " and payer='"+payerCode+"' and invoiceNo='" + invoiceNo + "' and feeInvoiceId != '" + feeInvoiceId + "' ";
                        C.syncRequest.callAction('list', 'feeInvoice', {_extend:countStr },function (action, domainName, resp) {
                                    count = resp.rows.length; });

                        if(companyCode && companyCode.substring(0,2)=="66"){
                            var extendSql = " and invoiceNo = '" + invoiceNo + "' and payee = '"+payeeCode1+"' and feeInvoiceId != '" + feeInvoiceId + "'"
                            C.syncRequest.callAction('list', 'feeInvoice', {_extend: extendSql},
                                    function (action, domainName, resp) {
                                        countSy = resp.rows.length;
                                    });
                        }
                    }
                }
                if(count>0){
                    if(!isEmpty(innerOrder)){
                        var tipstr = ("已存在在发票号为")+invoiceNo+("订单号为")+innerOrder+("且付款单位为")+payerName+("的记录，是否继续保存");
                        if(youlunFlag){tipstr = ("已存在在发票号为")+invoiceNo+("订单号为")+innerOrder+("且开票单位为")+payeeName1+("的记录，是否继续保存");}
                        if(!confirm(tipstr)){ return false  }
                    }else{
                        var tipstr = ("已存在在发票号为")+invoiceNo+("且付款单位为")+payerName+("的记录，是否继续保存");
                        if(youlunFlag){tipstr = ("已存在在发票号为")+invoiceNo+("且开票单位为")+payeeName1+("的记录，是否继续保存");}
                        if(!confirm(tipstr)){ return false  }
                    }
                }
                if(countSy>0){
                    var tipstr = ("已存在在发票号为")+invoiceNo+("且开票单位为")+payeeName1+("的记录，是否继续保存");
                    if(!confirm(tipstr)){ return false  }
                }

                if(companyCode && companyCode.substring(0,2)=="66"){
                    var validateNum = 0
                    var validateOrderNo = ""
                    var vesselCode = page.getEditBox().getExtField("vesselCode").getValue()
                    C.syncRequest.callAction('validateInvoice', 'compenPaymentsSanYun', {invoiceNo: invoiceNo,receiver:payeeCode1,vesselCode:vesselCode},
                            function (action, domainName, resp) {
                                if(resp && resp.id){
                                    validateNum = resp.id;
                                    validateOrderNo = resp.msg;
                                }
                            });
                    if(validateNum > 0){
                        var tipstr = "当前录入的的发票在业务管理-保险管理-事故理赔界面的事故费支付存在相同的记录，内部订单号为:"+validateOrderNo+"，请检查是否继续保存?";
                        if(!confirm(tipstr)){ return false}
                    }
                }

                //厦门远洋通导修备费 订单号必填
                if(xiamenFlag && invoiceSortValue == "FY67" && isEmpty(innerOrder)){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号。")
                    return false
                }
                //中远海运特种运输有限公司 发票录入（新版）模块，2019年及以后的费用类别中“厂修费、航修费、检验费、通导修备费“四类费用录入时，
                // 调整为订单号为必填项必填 检验费、通导修备费不必填
                var foreStatMonth = page.getEditBox().getExtField('foreStatMonth').getValue();
                if(!isEmpty(companyCode) && (companyCode.substring(0,2)=='65')
                        && isEmpty(innerOrder) && Number(new Date(foreStatMonth).getFullYear()) > 2018 &&
                        ( invoiceSortValue == "FY61" ||invoiceSortValue == "FY62")){
//                          ||  invoiceSortValue == "FY05" ||invoiceSortValue == "FY67" )){//通导修备费暂时去掉校验
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号。")
                    return false
                }
                //付款单位
                C.syncRequest.callAction('callSpManagement','feeInvoice',{vesselCode:page.getEditBox().getExtField("vesselCode").getValue(),
                            date:enquireMainApplyDate,manageType:'6',currentCompany:'<%=user.getCompanyCode()%>'},
                        function(action,domainName,resp){
                            if(resp && resp.rows && resp.rows.length>0){
                                validatePayerCode = resp.rows[0].MANAGEMENT_CODE
                                validatePayerName = resp.rows[0].MANAGEMENT_NAME
                            }
                        });
                //68公司不走验证付款单位是否一致逻辑-68公司并且费用类别是绑扎件的付款单位一直是集运
                if(companyCode&&!companyCode.substring(0,2)=='68'&&!isEmpty(validatePayerCode)){
                    if(!(payerCode == validatePayerCode)){
                        if(confirm(CSIS.Lang.ID_237650||"当前付款单位与完工日期所对应的付款单位不一致，是否更新为当前完工日期的付款单位？")){
                            tempFields.put("validatePayerCode",validatePayerCode)
                            tempFields.put("validatePayerName",validatePayerName)
                            page.getEditBox().getExtField("payer").setComboValue(validatePayerCode,validatePayerName)
                        }
                    }
                }
                //begin 20170310 wangr 录入发票时，如果是厂修备件，则校验：选择的关联数据订货标示必须是修船
                var invoiceSortValue = page.getEditBox().getExtField('invoiceSort').getComboValue().value;
                var invoiceSortDetailValue = page.getEditBox().getExtField('invoiceSortDetail').getComboValue().value;
                var innerOrderStr = page.getEditBox().getExtField('innerOrder').getValue();
                var checkOIflag=false; var checkMsg;
                if(youlunFlag&&!isEmpty(invoiceSortValue)&&!isEmpty(invoiceSortDetailValue)&&!isEmpty(innerOrderStr)){
                }else{
                    if(innerOrderStr!=""&&invoiceSortDetailValue!=""){
                        C.syncRequest.callAction("checkOrderInvoice","feeInvoice",{innerOrder:innerOrderStr,invoiceSortDetail:invoiceSortDetailValue},
                                function(action,domain,resp){  if(resp.msg=="1"){  checkOIflag=true;}  })
                    }
                    if(checkOIflag && !haiteFlag){
                        if(!confirm(CSIS.Lang.ID_237660||"费用科目与订单类别不一致，请核对费用科目是否正确，点击“确定”按钮，\n费用将按照发票费用科目进行统计。")){
                            return false }
                    }
                }

                if(invoiceSortValue=='FY63' && invoiceSortDetailValue=='FY63001') {
                    var isRepair = false;
                    var _extend = 'and orderType = \'F\' and enquireNo =\'' + page.getEditBox().getExtField('innerOrder').getComboValue().value + '\'';
                    C.syncRequest.callAction('list', 'enquireMainVo', {_extend: _extend},
                            function (action, domainName, resp) {
                                if (resp.rows.length == 0) { isRepair = true;  }
                            })
                    if (isRepair) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_140450||"如果是厂修备件，选择的关联数据订货标示必须是修船！");
                        return false;
                    }
                }
                //end
                var invoiceSortDetail=   page.getEditBox().getExtField('invoiceSortDetail').getComboValue().display;
                if((!daYuanFlag&&!companyCode.startWith("1331")&&!companyCode.startWith("6207")&&!companyCode.startWith("0811"))&&(CSIS.Lang.ID_140440||"油公司检验费")==invoiceSortDetail&&IsYYfee==false){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"针对油轮公司费用科目为油公司检验费的数据，只有辛钢、张欣、王洪波可以操作！");
                    return false;
                }
                if(youlunFlag){  //中海能源
                    page.getEditBox().setValue("isFixedAsset",false);  //固定资产强制为false
                    if(!daYuanFlag){
                        if((invoiceSortValue=='FY01'&&(invoiceSortDetailValue=='FY01001'||invoiceSortDetailValue=='FY01002'||invoiceSortDetailValue=='FY01007'))||
                                invoiceSortValue=='FY06'){
                        }else{
                            if(isEmpty(invoiceNo)||isEmpty(invoiceDate)){
                                Ext.MessageBox.alert('系统提示', "除修理费、技改费外，其他费用均需要在保存时录入发票号、发票日期等发票信息！");
                                return false;
                            }
                            if(invoiceNo.indexOf("|")<0&&invoiceNo.length>20){
                                Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "发票号长度不能超过20位！");
                                return false;
                            }
                        }
                    }
                    if(daYuanFlag||companyCode.substring(0,4)=='0811'||companyCode.substring(0,4)=='1331'){
                        if(isEmpty(invoiceNo)||isEmpty(invoiceDate)){
                            Ext.MessageBox.alert('系统提示', "发票号、发票日期不能为空！");
                            return false;
                        }
                        if(invoiceNo.indexOf("|")<0&&invoiceNo.length>20){
                            Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "发票号长度不能超过20位！");
                            return false;
                        }
                    }
                    var voyageNo = page.getEditBox().getExtField('voyageNo').getValue();
                    var portCode = page.getEditBox().getExtField('portCode').getValue();
                    var vesselCode = page.getEditBox().getExtField('vesselCode').getValue();
                    var payer = page.getEditBox().getExtField('payer').getValue();
                    if( (invoiceSortValue=='FY69'&&invoiceSortDetailValue!='FY69010')||invoiceSortValue == 'FYR1' ){
                        if(isEmpty(voyageNo)||isEmpty(portCode)){
                            Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "该费用类别及科目，需输入航次号、港口");
                            page.getEditBox().getExtField('voyageNo').focus();
                            return false;
                        }else { //如果是期租航次，需要判断航次是否转化  isChangeQTC
                            var isFlag = true;  var voyageMsg = "";

                            C.syncRequest.callAction('checkVesselVoyageNoforPay','feeInvoice',
                                    {voyageNo:voyageNo,vesselCode:vesselCode,portCode:portCode,invoiceSort:invoiceSortValue,invoiceSortDetail:invoiceSortDetailValue,payee:payeeCode1},function(action,domainName,resp){
                                isFlag = resp.success;
                            });
                            if(isFlag){
                                if(!confirm("该船舶该航次该港口已经付过款，点击“确定”按钮，\n该航次将继续录入发票付款。")){ return false }
                             }
                        }
                    }
                    var vesselCodeStr = page.getEditBox().getExtField('vesselCode').getValue();
                    vesselCodeStr = "'"+vesselCodeStr+  "'";
                    if(!isEmpty(payerCode)&&!isEmpty(payeeCode1)&&!daYuanFlag){
                        var isSupperCode = true;
                        var checkpayerCode = payerCode;
                        if(checkpayerCode.substring(0,4)=='0802'||checkpayerCode.startWith('0806')){
                            checkpayerCode = '080200000000';
                        }
                        C.syncRequest.callAction('getSupperCodeByCondeition','feeInvoice',{payer:checkpayerCode,payee:payeeCode1},function(action,domainName,resp){
                            isSupperCode = resp.success;
                        });

                    if(!isSupperCode){
                            Ext.MessageBox.alert("系统提示","开票单位对应财务供应商代码缺失,请去客商信息中维护");
                            return false;
                        }
                    }

                    var currency = page.getEditBox().getExtField('currency').getValue();
                    var invoiceSort = page.getEditBox().getValue('invoiceSort')
                    var isInputFlag = true;
                    if(currency=='CNY'&&payer!=null&&(payer.startWith("08020000")||payer.startWith("08020100"))
                        &&!(invoiceSort=='FY69'||invoiceSortDetail=='FY01012'||invoiceSortDetail=='FY01013')){
                        C.syncRequest.callAction('checkNYInputFeeCode','feeInvoice',
                            {vesselCode:vesselCode,payer:payer,currency:currency,invoiceSort:invoiceSortValue,invoiceSortDetail:invoiceSortDetailValue},function(action,domainName,resp){
                                isInputFlag = resp.success;
                            });
                        if(!isInputFlag){
                            Ext.MessageBox.alert("系统提示","当前船舶不可使用能源或海南能源作为付款单位，录入人民币发票；单船公司人民币发票，可使用其母公司进行录入");
                            return false;
                        }
                    }
                }
                //重新设置录入人和录入日期
                if(isCreate){page.getEditBox().setValue('inputDate',new Date());}
                //20170912 by yaotao 保存时校验库存管理和固定资产勾选框不能同时有值(青远和油运暂不考虑)
                var ifJigaiCmp = page.getEditBox().getExtField('ifJigai');
                var isFixedAssetCmp = page.getEditBox().getExtField('isFixedAsset');
                if(ifJigaiCmp && isFixedAssetCmp){
                    if(ifJigaiCmp.getValue() == 1 && isFixedAssetCmp.getValue() == 1){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_238050||"库存管理和固定资产不能同时勾选！");
                        return false;
                    }
                }
                //4.对于散运，编辑发票保存时，需要校验如果已经有关联信息，界面上的库存管理的标记，就不允许修改。
                var haveRelevant = false;
                if(manager.startWith('66') && isCreate==false && ifJigaiCmp.getValue()!= currentRecord.ifJigai ){//散运编辑情况库存管理改掉了
                    C.syncRequest.callAction('list', 'operationRelevance', {feeInvoiceId: currentRecord.feeInvoiceId},
                            function (action, domainName, resp) {
                                if (resp.rows.length > 0) {
                                    haveRelevant = true;
                                }
                            })
                    if(haveRelevant==true) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160 || '系统提示', CSIS.Lang.ID_238051 || "已经有关联信息时，库存管理不能修改！");
                        return false;
                    }
                }
                //66散運,是否属安全费勾选时，安全费类别必填;  安全费类别已填内容时，是否属安全费必須勾選
                var safeFlag = page.getEditBox().getExtField('safeFlag');
                var safeItem = page.getEditBox().getExtField('safeItem');
                if(safeFlag&&safeItem){
                    if(manager.startWith('66') && safeFlag.getValue() == 1 && isEmpty(safeItem.getValue()) ){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_238061||"是否属安全费勾选时，请选择输入安全费类别！");
                        return false;
                    }
                    if( !isEmpty(safeItem.getValue()) && safeFlag.getValue() != 1  ){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_238062||"安全费类别已填内容时，请勾选上是否属安全费！");
                        return false;
                    }

                }
                //当费用类别为修理费或检验费时，完工日期必填
                var invoiceSort = page.getEditBox().getValue('invoiceSort');
                var invoiceSortDetail = page.getEditBox().getValue('invoiceSortDetail');
                var occurTimeFrom = page.getEditBox().getValue('occurTimeFrom');
                var payee = page.getEditBox().getValue('payee');
                var payer = page.getEditBox().getValue('payer');
                var payerName = page.getEditBox().getExtField("payer").getComboValue().display;
                var billNo = page.getEditBox().getValue('billNo');
                var signNo = page.getEditBox().getValue('signNo');
                var orderNo = page.getEditBox().getValue('orderNo');
                var vesselCode = page.getEditBox().getExtField("vesselCode").getValue();
                if((invoiceSort == 'FY65' && invoiceSortDetail == 'FY65002') && ("66190000" == payer||"66000000" == payer||"66180000" == payer)&&ifJigaiCmp.getValue() != 1){
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","【"+payerName+(CSIS.Lang.ID_238060||"】的日常保养油漆费必须勾选库存管理，请对库存管理方框打钩！"));
                    return false;
                }
                if((invoiceSortDetail == 'FY65002' || invoiceSortDetail == 'FY04001') && "08011100" == payer && ifJigaiCmp.getValue() != 1){
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","【"+payerName+(CSIS.Lang.ID_238060||"】的日常保养油漆费必须勾选库存管理，请对库存管理方框打钩！"));
                    return false;
                }

                //特运的发票，包含沥青,company 是65开头,费用类别为物料,库存管理的复选框 选中
                if(invoiceSort == 'FY04' && manager.startWith('65') && ifJigaiCmp.getValue() == 1){
                    if(!confirm("已勾选库存管理，是否确认对该票进行库存管理？")) {
                        return false;
                    }
                }
                if(("66190000" == payer||"66180000" == payer||"66000000" == payer||manager.startWith('6603')||"63000000" == payer)&&(invoiceSort=='FY63'||invoiceSort=='FY04')&&!isEmpty(innerOrder)&&payer!="08011100"){
                    var flag = false;
                    var checkType = '';
                    if(invoiceSort=='FY63'){
                        checkType = 'BJ'
                    }else if(invoiceSort=='FY04'||invoiceSort=='FY65'){
                        checkType = 'WL'
                    }
                    //校验库存管理
                    CSIS.syncRequest.callAction('checkInventoryManagement','feeInvoice',{innerOrder:innerOrder,vesselCode:vesselCode,checkType:checkType},function(a,b,c){
                        flag = c.success;
                    });
                    if(!flag&&!confirm(CSIS.Lang.ID_238110||"系统检查到该订单包含重大库存管理物资，可能需要勾选库存管理。请检查是否需要勾选库存管理！\n继续保存点确定，否则请点取消按钮。")){
                        return false;
                    }
                }

                //时代航运公司， 物料费 -缆绳FY04002 检验库存管理必填
                if(payer=="08011100" && invoiceSort=='FY04' && invoiceSortDetail=='FY04002' && !isEmpty(innerOrder)){
                    var flg = false;
                    //校验库存管理
                    CSIS.syncRequest.callAction('checkInventoryManagement','feeInvoice',{innerOrder:innerOrder,vesselCode:vesselCode,checkType:'WL'},function(a,b,c){
                        flg = c.success;
                    });
                    var ifJigai = page.getEditBox().getValue('ifJigai');
                    if(!flg && !ifJigai){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||"系统提示","系统检查到该订单包含重大库存管理物资，<br>可能需要勾选库存管理。请检查是否需要勾选库存管理！");
                        return false;
                    }
                }

                if(payer=="08011100"){
                    var payeeName = page.getEditBox().getExtField('payee').getComboValue().display;
                    if((payeeName.indexOf("缆绳") != -1 || payeeName.indexOf("绳缆") != -1) && invoiceSortDetail!='FY04002'){
                        if(!confirm("根据本单开票单位名称可能费用小类应该选“缆绳”费，请确认当前录入是否正确并保存？")) {
                            return false;
                        }
                    }
                }



                if(payer=="08011100" && (invoiceSort=='FY49' || invoiceSort=='FY62')){
                    if(isEmpty(innerOrder) && occurTimeFrom
                        && Ext.util.Format.date(occurTimeFrom,'Y-m-d') >= Ext.util.Format.date("2023-09-01",'Y-m-d')){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号！");
                        return false;
                    }
                }

                //时代航运公司检验
                if(payer=="08011100"){
                    if(isEmpty(innerOrder) && invoiceSort=="FY04" && invoiceSortDetail!="FY04103" && invoiceSortDetail!="FY04110"){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号！");
                        return false;
                    }
                    if(isEmpty(innerOrder) && invoiceSortDetail=="FY63002"
                            && Ext.util.Format.date(new Date(),'Y-m-d') >= Ext.util.Format.date("2024-04-25",'Y-m-d')){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号！");
                        return false;
                    }
                    if(isEmpty(innerOrder) && invoiceSort=="FY05"
                        && !isEmpty(foreStatMonth) && Number(new Date(foreStatMonth).getFullYear()) >= 2024){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"订单号不能为空，请填写订单号！");
                        return false;
                    }
                    if(invoiceSort=="FY61"){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"当前费用类别默认了厂修费，不符合时代航运名称要求，请修改为计修费！");
                        return false;
                    }
                    if(invoiceSort=="FY51" && Ext.util.Format.date(new Date(),'Y-m-d') > Ext.util.Format.date("2024-09-05",'Y-m-d')){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "从即日起，船长借支类费用切换其他模块录入了，不需要在当前版面中录入了！");
                        return false;
                    }
                    if(invoiceSort=="FY51" && !isEmpty(invoiceNo) && invoiceNo.length>20){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "发票号长度不能超过20位！");
                        return false;
                    }
                }

                if(tianjinFlag){
                    if(invoiceSort != 'FY19' && !occurTimeFrom){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_242590||"请填写发生（完工）日期",function(){
                            page.getEditBox().getExtField('occurTimeFrom').focus();
                        });
                        return false;
                    }
                }
                if(youlunFlag){
                    var innerOrder = page.getEditBox().getExtField('innerOrder').getValue();
                    if(invoiceSort == 'FY06'&&!isEmpty(innerOrder)&&!isEmpty(billNo)){
                        var ifCheckPass = true; var returnCheckMsg;
                        C.syncRequest.callAction('checkBillNoIsSame','feeInvoice',{billNo:billNo,innerOrder:innerOrder,vesselCode:vesselCode},function(action,domainName,resp){
                            if(resp){ ifCheckPass = resp.success; returnCheckMsg=resp.msg; }
                        })
                        if(!ifCheckPass) {
                            Ext.MessageBox.alert("系统提示",returnCheckMsg);  return false;
                        }
                    }
                    //油运只有当 FYO1并且费用科目为厂休才进行校验
                    if((invoiceSort == 'FY01' && invoiceSortDetail == 'FY01001')){
                        if( !occurTimeFrom){
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140480||"请填写完工日期",function(){
                                page.getEditBox().getExtField('occurTimeFrom').focus();
                            });
                        }
                        var innerOrder = page.getEditBox().getExtField('innerOrder').getValue(); //判断是否选择厂修订单号
                        if(isEmpty(innerOrder)){
                            Ext.MessageBox.alert("提示","请选择订单号",function(){ page.getEditBox().getExtField('innerOrder').focus(); });
                            return false;
                        }
                    }
                    if((invoiceSort == 'FY01' && ( invoiceSortDetail == 'FY01001'||invoiceSortDetail == 'FY01002'||invoiceSortDetail == 'FY01004'||invoiceSortDetail == 'FY01007') )
                            ||invoiceSort == 'FY04'||invoiceSort == 'FY43'||invoiceSort == 'FY06'
                            ||invoiceSortDetail=='FY16002'||(invoiceSort == 'FY13'&&invoiceSortDetail!='FY13015'&&invoiceSortDetail!='FY13017'&&invoiceSortDetail!='FY13012'
                            &&invoiceSortDetail!='FY13010')){  //备件和物料费，必须关联订单号
                        var innerOrder = page.getEditBox().getExtField('innerOrder').getValue();
                        if(isEmpty(innerOrder)){
                            Ext.MessageBox.alert("提示","备件、物料、技改、厂修、航修、船舶证书费、通导，船员劳动保护费、防疫物资费类型必须关联订单号",function(){
                                page.getEditBox().getExtField('innerOrder').focus();
                            });
                            return false;
                        }
                    }
                    //对油运的船舶，增加 技改费，技改其他 费用时，内部订单号必须输入的 逻辑校验
                    if((invoiceSort == 'FY06')||invoiceSort=='ZCF'||invoiceSortDetail=='FY01001'||invoiceSortDetail=='FY04109'){
                        if(isEmpty(billNo)){
                            Ext.MessageBox.alert("提示","当费用类别为‘技改费、厂修、造船费、厂修物料费’，必须输入关联单号",function(){ page.getEditBox().getExtField('billNo').focus(); });
                            return false; }
                        var foreStatMonth = page.getEditBox().getValue('foreStatMonth');
                        var isExistBillNo=true; var extistBillNoMsg="";
                        if(!isEmpty(vesselCode)&&!isEmpty(invoiceSortDetail)&&!isEmpty(foreStatMonth)){
                            C.syncRequest.callAction('checkInnerOrderNoIsCorrect','jgInnerOrder',{year:foreStatMonth,vesselCode:vesselCode,innerOrder:billNo,
                                invoiceSort:invoiceSort,invoiceSortDetail:invoiceSortDetail},function(action,domainName,resp){
                                if(resp){ isExistBillNo =resp.success;  extistBillNoMsg = resp.msg; }
                            })
                        }
                        if(!isExistBillNo){
                            Ext.MessageBox.alert("提示",extistBillNoMsg,function(){ page.getEditBox().getExtField('billNo').focus();});
                            return false;
                        }
                    }
                    var ifJigai = page.getEditBox().getValue('ifJigai'); //库存管理
                    if(invoiceSort == 'FY01' && (invoiceSortDetail == 'FY01004')){  //备件
                        var innerOrder = page.getEditBox().getExtField('innerOrder').getValue();
                        if(!isEmpty(innerOrder)&&!ifJigai){
                            var returnMsg = "";
                            C.syncRequest.callAction('checkVesselStorage','feeInvoice',{innerOrder:innerOrder,ifJigai:ifJigai},
                                    function(action,domainName,resp){
                                if(resp&&resp.msg){
                                    returnMsg = resp.msg;
                                }
                            })
                            if(!isEmpty(returnMsg)){ Ext.MessageBox.alert("系统提示",returnMsg); return false;}
                        }
                    }
                }else{
                    if((invoiceSort == 'FY01' || invoiceSort == 'FY05') && !occurTimeFrom){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140480||"请填写完工日期",function(){
                            page.getEditBox().getExtField('occurTimeFrom').focus();
                        });
                        return false;
                    }
                }
                if(isCreate&&manager.startWith('66')){
                    var validateBillNo = true; var validateBillNoMag = "";
                    C.syncRequest.callAction('validateBillNo','jgInnerOrder',{vesselCode:vesselCode,billNo:billNo},function(action,domainName,resp){
                        if(resp&&!resp.success){
                            validateBillNo = resp.success;
                            validateBillNoMag = resp.msg;
                        }
                    })
                    if(!validateBillNo){
                        Ext.MessageBox.alert("提示",validateBillNoMag);
                        return false;
                    }
                }

                var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                if(exchangeRate<=0){
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236900||'汇率不能为0',function(){
                        page.getEditBox().getExtField('exchangeRate').focus();
                    });
                    return false;
                }

                var currency = page.getEditBox().getValue('currency');
                if (isEmpty(currency)) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",'币种不能为空',function(){
                        page.getEditBox().getExtField('currency').focus();
                    });
                    return false;
                }
                if (currency == 'CNY'&&exchangeRate != 1) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","币种为人民币，汇率应为1",function(){
                        page.getEditBox().getExtField('exchangeRate').focus();
                    });
                    return false;
                }
                var exchangeRateNew;
                C.syncRequest.callAction('getCurRate','exchangeRate',{currencyFrom:currency,currencyTo:'CNY'},
                    function(action,domainName,resp){
                        exchangeRateNew = resp;
                    });
                if (Number(exchangeRate)<Number(exchangeRateNew)*0.8||Number(exchangeRate)>Number(exchangeRateNew)*1.2) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","汇率和当前币种折算汇率("+exchangeRateNew+")相差超过20%，请检查",function(){
                        page.getEditBox().getExtField('exchangeRate').focus();
                    });
                    return false;
                }

                if(page.getEditBox().getExtField('zfExchangeRate')) {
                    var zfExchangeRate = Number(page.getEditBox().getValue('zfExchangeRate'));
                    if(zfExchangeRate<=0){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238250||'杂费汇率不能为0',function(){
                            page.getEditBox().getExtField('zfExchangeRate').focus();
                        });
                        return false;
                    }
                }

                if(companyCode.startWith("0200")&&invoiceSortValue=='FY01'){
                    var reVerify = verifyAmountKeFY01();
                    if(reVerify==false)return false;
                }else{
                    if(companyCode.startWith("0200")&&invoiceSortValue!='FY01'){
                        var fy01Map = new C.HashMap();
                        fy01Map.put("invoiceNo",page.getEditBox().getValue('invoiceNo'));   //发票号
                        fy01Map.put("invoiceDate",page.getEditBox().getValue('invoiceDate')); //发票日期
                        fy01Map.put("amountWithoutTax",page.getEditBox().getValue('amountWithoutTax'));  //不含税总金额
                        fy01Map.put("taxAmount",page.getEditBox().getValue('taxAmount'));  //发票总税额
                        fy01Map.put("amount",page.getEditBox().getValue('amount')); //发票总金额
                        fy01Map.put("dtlAmountWithoutTax",page.getEditBox().getValue('dtlAmountWithoutTax')); //不含税金额
                        fy01Map.put("dtlTaxAmount",page.getEditBox().getValue('dtlTaxAmount'));  //税额
                        fy01Map.put("dtlAmount",page.getEditBox().getValue('dtlAmount')); //含税金额
                        fy01Map.put("baseAmount",page.getEditBox().getValue('baseAmount'));  //人民币金额

                        var reisNullVerify = verifyIsNullKeFY01(fy01Map,"");
                        if(reisNullVerify==false)return false;
                    }

                    var ifTaxtRate = page.getEditBox().getValue('taxRate');
                    if(ifTaxtRate!='其他'){  //金额一些基本验证
                        //验证发票金额
                        var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                        var taxAmount = Number(page.getEditBox().getValue('taxAmount'));
                        var amount = Number(page.getEditBox().getValue('amount'));
                        var taxRate = Number(page.getEditBox().getValue('taxRate'));
                        //发票总税额根据税率计算值的1%上下浮动
                        var taxAmountMax = amountWithoutTax * (taxRate + 0.01)
                        var taxAmountMin = amountWithoutTax * (taxRate - 0.01)

                        if (amountWithoutTax==0&&taxAmount==0) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140500||"发票不含税总金额和发票总税额不能都等于零",function(){
                                page.getEditBox().getExtField('amountWithoutTax').focus();
                            });
                            return false;
                        }
                        if(taxRate != 0) {
                            if(Math.abs(taxAmount) > Math.abs(taxAmountMax) || Math.abs(taxAmount) < Math.abs(taxAmountMin) ) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238040||"发票总税额超过了根据税率计算值的1%，请检查并修改！",function(){
                                    page.getEditBox().getExtField('taxAmount').focus();
                                });
                                return false;
                            }
                        } else {
                            if(taxAmount != 0 && !isEmpty(invoiceSortValue) && invoiceSortValue!= 'FY16') {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238030||"当前记录的税率为0,发票总税额不等于0，请检查并修改！",function(){
                                    page.getEditBox().getExtField('taxAmount').focus();
                                });
                                return false;
                            }
                        }

                        if (amount != (amountWithoutTax + taxAmount).toFixed(2)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236920||"发票不含税总金额 加 发票总税额 不等于 发票总金额",function(){
                                page.getEditBox().getExtField('amountWithoutTax').focus();
                            });
                            return false;
                        }

                        //验证明细金额
                        var dtlAmount = Number(page.getEditBox().getValue('dtlAmount'));
                        var dtlAmountWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var dtlTaxAmount = Number(page.getEditBox().getValue('dtlTaxAmount'));


                        //税额根据税率计算值的1%上下浮动
                        var dtlTaxAmountMax = dtlAmountWithoutTax * (taxRate + 0.01)
                        var dtlTaxAmountMin = dtlAmountWithoutTax * (taxRate - 0.01)
                        if (dtlAmountWithoutTax==0&&dtlTaxAmount==0) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140510||"不含税金额和税额不能都等于零",function(){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                            });
                            return false;
                        }
                        if(taxRate != 0 && !isEmpty(invoiceSortValue) && invoiceSortValue!= 'FY16') {
                            if(Math.abs(dtlTaxAmount) > Math.abs(dtlTaxAmountMax) || Math.abs(dtlTaxAmount) < Math.abs(dtlTaxAmountMin) ) {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238010||"税额超过了根据税率计算值的1%，请检查并修改！",function(){
                                    page.getEditBox().getExtField('dtlTaxAmount').focus();
                                });
                                return false;
                            }
                        } else {
                            if(dtlTaxAmount !=  0 && !isEmpty(invoiceSortValue) && invoiceSortValue!= 'FY16') {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238000||"当前记录的税率为0,税额不等于0，请检查并修改！",function(){
                                    page.getEditBox().getExtField('dtlTaxAmount').focus();
                                });
                                return false;
                            }
                        }

                        if (dtlAmount != (dtlAmountWithoutTax + dtlTaxAmount).toFixed(2)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236940||"不含税金额 加 税额 不等于 含税金额",function(){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                            });
                            return false;
                        }
                        page.getEditBox().setValue('baseAmountWithoutTax',(dtlAmountWithoutTax*exchangeRate).toFixed(2));
                    }else{
                        //验证发票金额
                        var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                        var taxAmount = Number(page.getEditBox().getValue('taxAmount'));
                        var amount = Number(page.getEditBox().getValue('amount'));
                        var taxRate = Number(page.getEditBox().getValue('taxRate'));

                        if (amountWithoutTax==0&&taxAmount==0) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140500||"发票不含税总金额和发票总税额不能都等于零",function(){
                                page.getEditBox().getExtField('amountWithoutTax').focus();
                            });
                            return false;
                        }

                        if (amount != (amountWithoutTax + taxAmount).toFixed(2)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236920||"发票不含税总金额 加 发票总税额 不等于 发票总金额",function(){
                                page.getEditBox().getExtField('amountWithoutTax').focus();
                            });
                            return false;
                        }

                        //验证明细金额
                        var dtlAmount = Number(page.getEditBox().getValue('dtlAmount'));
                        var dtlAmountWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var dtlTaxAmount = Number(page.getEditBox().getValue('dtlTaxAmount'));

                        if (dtlAmountWithoutTax==0&&dtlTaxAmount==0) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140510||"不含税金额和税额不能都等于零",function(){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                            });
                            return false;
                        }

                        if (dtlAmount != (dtlAmountWithoutTax + dtlTaxAmount).toFixed(2)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236940||"不含税金额 加 税额 不等于 含税金额",function(){
                                page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                            });
                            return false;
                        }
                        page.getEditBox().setValue('baseAmountWithoutTax',(dtlAmountWithoutTax*exchangeRate).toFixed(2));

                        page.getEditBox().setValue('taxRate',"");
                    }
                }

                var taxRate = Number(page.getEditBox().getValue('taxRate'));
                if (taxRate == 0) {
                    tempFields.put("taxRateName","0");
                } else {
                    tempFields.put("taxRateName",(taxRate*100)+"%");
                }

                var invoiceSort = page.getEditBox().getValue('invoiceSort')
                if(isCreate){
                    var payer = page.getEditBox().getValue('payer')
                    if(companyCode.startWith("6601")){
                        payer = companyCode;
                    }
                    var time =C.ServerTimeIE
                    var _extend = " AND (typeCode = '" +invoiceSort+"' or typeCode is null)"+
                            " AND mtbl.lockedCompany = '" +payer+"'"+
                            " AND to_char(mtbl.dateFrom,'yyyy/MM/dd') <= '" + time +"' "+
                            " AND to_char(mtbl.dateTo,'yyyy/MM/dd') >= '" + time +"')" +
                            " AND isDelete ='0'" ;
                    var isLocked = false;
                    C.syncRequest.callAction('list','lockedRule',{lockedType:'FREIGHT_TYPE',_extend:_extend},function(action,domainName,resp){
                        if(resp&&resp.rows&&resp.rows.length>0){
                            isLocked = true;
                        }
                    })
                    if(isLocked){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140520||"该费用类型已经锁定，无法继续录入该费用！",function(){
                            page.getEditBox().getExtField('invoiceSort').focus();
                        });
                        return false;
                    }
                }
                var invoiceSortDetail = page.getEditBox().getValue('invoiceSortDetail')
                var ifJigai = page.getEditBox().getValue('ifJigai')
                if(!(payer&&payer.startWith('91'))&&!(invoiceSort == 'FY04'||invoiceSortDetail=='FY01004' || invoiceSort == 'FY63' || invoiceSort == 'FY65' || invoiceSort == 'FY03' || invoiceSort == 'FY33')&&ifJigai){
                    if(youlunFlag){
                        if(invoiceSort != 'FY06'){
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","只有费用是备件、物料、油漆、滑油、技改的才能选库存管理!");
                            return false;
                        }
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238230||"只有费用是备件、物料、油漆、滑油的才能选库存管理!");
                        return false;
                    }
                }
                var checkFlage =false;
                var CoscoSap = "";
                C.syncRequest.callAction('getIfSendCoscoSap', 'feeInvoice', {payer: payer},
                        function (action, domainName, resp) {
                            var ifSendCoscoSap = resp.msg.split(",")[0];
                            var ifSendSap = resp.msg.split(",")[1];
                            if (resp.success) {
                                if(ifSendCoscoSap=='1'){  ////中远
                                    CoscoSap = "1"
                                    if(!verifyExistsSAP(payee,payer,'COSCO_SUPPLIER') ){
                                        checkFlage =true;
                                        return false;
                                    }
                                }else if(ifSendSap=='1'){  //中海
                                    if(!verifyExistsSAP(payee,payer,'SUPPLIER')){
                                        checkFlage =true;
                                        return false;
                                    }
                                }
                            }
                        });
                if(!isEmpty(CoscoSap)&&("0801"==payer.substring(0,4)||"66"==payer.substring(0,2))&&
                        ((invoiceSort == 'FY61'||invoiceSort=='FY06'||invoiceSort=='FY49'||invoiceSortDetail=="FY04021"||invoiceSortDetail=="FY04109"||invoiceSortDetail=="FY63001"
                                ||invoiceSortDetail=="FY64001"||invoiceSortDetail=="FY64002"||invoiceSortDetail=="FY65001"||invoiceSortDetail=="FY64011"))){
                    if(isEmpty(billNo)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_238220||"内部订单号不能为空，请填写后再保存！");
                        return false;
                    }
                }

                if(checkFlage&&!confirm(CSIS.Lang.ID_236950||"该开票单位还没有SAP代码，请向财务申请增加该供应商！\n对该记录是否继续保存？")){
                    return  false;
                }
                var miscAmount = Number(page.getEditBox().getValue('miscAmount')?page.getEditBox().getValue('miscAmount'):0)
                var sercAmount = Number(page.getEditBox().getValue('sercAmount')?page.getEditBox().getValue('sercAmount'):0)
                var otherAmount = Number(page.getEditBox().getValue('otherAmount')?page.getEditBox().getValue('otherAmount'):0)
                if(miscAmount + sercAmount + otherAmount!=0) {
                    if(amount>=0){
                        if (amount < (miscAmount + sercAmount + otherAmount)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", CSIS.Lang.ID_140530||"运杂费，服务费及其他费用的总金额不能超过发票总金额", function () {
                            });
                            return false;
                        }
                    }
                }
                if(!(tianjinFlagTwo && invoiceSort == 'FY63' && !isEmpty(innerOrder))){
                    var payer = page.getEditBox().getValue('payer');
                    if(!isEmpty(payer)&&payer.substring(0,2)=='66'){
                        if(billNoFlag &&!confirm(CSIS.Lang.ID_238200||"由内部订单号带出的关联信息将替代原来的关联信息！\n对该记录是否继续保存？")){
                            return false;
                        }
                    }
                }

                if(companyCode.substring(0,2)=='66' && !isEmpty(billNo) && billNo.length!=12){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', "内部订单号单号规则(12位)不对，请检查是否正确。");
                    return false;
                }

                //当付款单位为集运及其下属单位时，费用类别的备注信息为XC或TD时，且有关联订单号，
                // 则取该订单号下的所有人民币金额合计与订单金额进行比较，如果大于订单金额，则弹出提示框，
                // 提示“因发票总金额大于订单预估金额，请输入理由”，当用户输入的理由不为空时，保存录入的发票信息；
                var validateBl = true
                //var orderFeeValidateMap = getCodedictMap('FMM_ORDER_FEE_VALIDATE');
                var orderFeeValidateMap = codedictMaps['FMM_ORDER_FEE_VALIDATE'];
                var excessReason = page.getEditBox().getExtField('excessReason').getValue();
                var baseAmount = page.getEditBox().getExtField('baseAmount').getValue();
                if(orderFeeValidateMap["FMM_ORDER_VALIDATE"]=="1"&&payer&&payer.startWith("68")&&isEmpty(excessReason)&&!isEmpty(innerOrder)){
                    C.syncRequest.callAction('orderFeeValidate','feeInvoice',{
                        innerOrder:innerOrder,invoiceSort:invoiceSort,baseAmount:baseAmount
                    },function(a,b,resp){
                        if(resp && resp.success && resp.msg.length>0){
                            Ext.MessageBox.alert("提示",resp.msg);
                            validateBl = false;
                        }
                    })
                }
                if(!validateBl){
                    page.getEditBox().getExtField('excessReason').focus();
                    return validateBl;
                }

                //PAYER是68开头，INVOICE_SORT是FY63的发票，如果订单号对应的订货标识是“索赔订货”，提醒，点确定后可以保存
                //共用validateBl标记
                var vlInnerOrderMsg = ""
                if(payer&&payer.startWith("68")&&invoiceSort&&invoiceSort=="FY63"&&innerOrder){
                    var vlInnerOrder = "'" + innerOrder.split(",").join("','") + "'";
                    C.syncRequest.callAction('innerOrderValidate','feeInvoice',{
                        innerOrder:vlInnerOrder
                    },function(a,b,resp){
                        if(resp && resp.success && resp.msg.length>0){
                            validateBl = false;
                            vlInnerOrderMsg = "订单号："+resp.msg+"为索赔订货，请慎重付款！";
                        }
                    })
                }

                if(!validateBl){
                    if(!confirm(vlInnerOrderMsg)){
                        return false
                    }
                }

                var ifCanUseTax = page.getEditBox().getExtField('ifCanUseTax').getValue();
                var currency = page.getEditBox().getExtField('currency').getValue();
                var payer = page.getEditBox().getExtField('payer').getValue();
                var energyCheck = true;
                if(companyCode.startWith('0802')){
                    if((invoiceSortValue=='FY01'&&(invoiceSortDetailValue=='FY01001'||invoiceSortDetailValue=='FY01002'||invoiceSortDetailValue=='FY01007'))||
                            invoiceSortValue=='FY06'){energyCheck=false}
                }
                debugger
                if (energyCheck&&(ifCanUseTax == '1'||ifCanUseTax=='2'||ifCanUseTax == '3'||ifCanUseTax == '4'||ifCanUseTax=='5'||ifCanUseTax=='6'||ifCanUseTax=='7')&&currency == 'CNY'&&invoiceCheckCompanyMap[payer]) {
                    if((ifCanUseTax == "6"||ifCanUseTax == "7") && (isEmpty(invoiceDate)||isEmpty(invoiceNo))&&invoiceCheckCompanyMap[payer]){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","当前付款公司增值税专用(电子)发票或者增值税普通(电子)发票 发票日期、发票号必填！");
                        return false
                    }else if(ifCanUseTax != "6" && ifCanUseTax != "7" && (isEmpty(invoiceDate)||isEmpty(invoiceCode)||isEmpty(invoiceNo))&&invoiceCheckCompanyMap[payer]){
                        if(companyCode.startWith('66')){
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","当前付款公司增值税专用(电子)发票或者增值税普通(电子)发票 发票日期、发票代码、发票号必填！");
                        }else{
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","当前付款公司增值税专用或者增值税普通发票 发票日期、发票代码、发票号必填！");
                        }
                        return false;
                    }
                    var payerName = page.getEditBox().getExtField('payer').rawValue;
                    var payeeName = page.getEditBox().getExtField('payee').rawValue;
                    if(payeeName){
                        payeeName = replacePayeeName(payeeName);
                    }
                    if(payerName){
                        payerName = replacePayeeName(payerName);
                    }

                    var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax')).toFixed(2);
                    if(ifCanUseTax=='6'||ifCanUseTax=='7'){
                        amountWithoutTax = Number(page.getEditBox().getValue('amount')).toFixed(2);
                    }
                    var taxCheckState = page.getEditBox().getExtField('taxCheckState').getValue();
                    var invoiceCheckCode = page.getEditBox().getExtField('invoiceCheckCode').getValue();
                    if ((ifCanUseTax=='2'||ifCanUseTax=='3'||ifCanUseTax=='4')&&isEmpty(invoiceCheckCode)) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","增值税普通发票校验码后六位必填！");
                        return false;
                    }
                    if (taxCheckState == '0') {
                        if (!isEmpty(salesName)&&(salesName.indexOf("税务总局")<0)&&(salesName.indexOf("代开")<0)&&(payeeName!="其他供应商－船员")&&(payeeName!="其他供应商")
                                &&(salesName!="秦皇岛市海港区税务局航信代开07")&&(salesName!="秦皇岛市海港区税务局航信代开05")&&(salesName!="江苏华海船舶管理有限公司" && salesName!="南京华海船务有限公司")) {
                            salesName = replacePayeeName(salesName);
                            if(salesName != payeeName){
                                var selectCount = 0
                                C.syncRequest.callAction('list', 'customer', {customerCode: payee,_extend:" and (customerName2 = '"+salesName+"' or paymentName = '"+salesName+"') "},
                                        function (action, domainName, resp) {
                                            if(resp.total && resp.total>0){
                                                selectCount = resp.total
                                            }
                                        });
                                if(selectCount==0){
                                    Ext.MessageBox.alert(CSIS.Lang.ID_117530 || "提示", "开票单位" + payeeName + "与税务系统返回的开票单位" + salesName + "不一致！");
                                    return false;
                                }
                            }
                        }

                        var payerFullName = "";
                        C.syncRequest.callAction('list','vwSysOrganizationInfo',{officeCode:payer},function(action,domainName,res){
                            if(res && res.rows && res.rows.length>0){
                                payerFullName = res.rows[0].fullName
                            }
                        });
                        if(payerFullName){
                            payerFullName = replacePayeeName(payerFullName);
                        }
                        if(purchaserName){
                            purchaserName = replacePayeeName(purchaserName);
                        }
                        if (!isEmpty(purchaserName)&&purchaserName.toLowerCase()!=payerName.toLowerCase()&&purchaserName.toLowerCase()!=payerFullName.toLowerCase()) {
                            if (!isEmpty(payerFullName) && payerName.toLowerCase()!=payerFullName.toLowerCase()){
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","付款单位"+payerName+"，"+payerFullName+"与税务系统返回的付款单位"+purchaserName+"不一致！");
                            } else {
                                Ext.MessageBox.alert(CSIS.Lang.ID_117530 || "提示", "付款单位" + payerName + "与税务系统返回的付款单位" + purchaserName + "不一致！");
                            }
                            return false;
                        }
                    }
                    if(!isEmpty(invoiceDate)&&!isEmpty(invoiceNo)) {
                        //全电增专普票发票代码不必填&&!isEmpty(invoiceCode)
                        var flag = checkFeeInvoice(invoiceCode,invoiceNo,invoiceDate,amountWithoutTax,invoiceCheckCode,page);
                        if (!flag) {
                            return false;
                        } else {
                            page.getEditBox().getExtField('taxCheckState').setValue('0');
                        }
                    }
                }
                //对于付款公司是080111；如果费用大类是SCF0扫舱费或者FY51船长借支，则根据费用小类查一下基础表
                // 图片里面这个“是否非营运”，如果这个没有勾，则必须录入航次和港口！！！提示语句可以是“当前费用类别”请填写航次港口 --》
                // 这个“当前费用类别”就直接用下拉框那个文字就行
                if(payer=="08011100" && (invoiceSort=="SCF0" || invoiceSort=="FY51")){
                    var invoiceSortName = page.getEditBox().getExtField("invoiceSort").getComboValue().display;
                    var falg = true;
                    if(!isEmpty(invoiceSortDetail)) {
                        C.syncRequest.callAction("list", "freight", {freightCode: invoiceSortDetail},
                            function (actionName, domainName, resp) {
                                var result = resp.rows
                                if (!isEmpty(result) && result.length > 0) {
                                    var row = result[0];
                                    if (row.isNonOperating != 1) {
                                        falg = false;
                                    }
                                }
                        });
                    }
                    if(!falg && (isEmpty(page.getEditBox().getExtField("portCode").getValue()) || isEmpty(page.getEditBox().getExtField("voyageNo").getValue()))){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","“"+invoiceSortName+"”请填写航次港口！");
                        return false;
                    }
                }


                if(payer=="08011100" && invoiceSort == 'FY63' && invoiceSortDetail == 'FY63002'){
                    if(!isEmpty(innerOrder)&&!ifJigai){
                        var returnMsg = "";
                        C.syncRequest.callAction('checkVesselStorage','feeInvoice',{innerOrder:innerOrder,ifJigai:ifJigai},
                            function(action,domainName,resp){
                                if(resp&&resp.msg){
                                    returnMsg = resp.msg;
                                }
                        })

                        if(!isEmpty(returnMsg)) {
                            Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示","单号"+innerOrder+"下存在库存管理备件，本发票没有勾选库存管理标记的方框！");
                            return false;
                        }
                    }
                }


                if(payer=="08011100" && (invoiceSortDetail == 'FY48004' ||
                    invoiceSortDetail == 'FY48005' || invoiceSortDetail == 'FY48014')){
                    if(!isEmpty(foreStatMonth) && Number(new Date(foreStatMonth).getFullYear()) >= 2024) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530 || "提示", "从2024年开始，检验费不再计入成本费，<br>请直接选择费用类别中的检验费后<br>再选择类别明细后保存！");
                        return false;
                    }
                }

                //时代航运公司，计修费，航修费，备件费，设备更新和技术改造费--智能船舶项目费用字段必填
                if(payer=="08011100" && (invoiceSort == 'FY62' || invoiceSort == 'FY63' || invoiceSort == 'FY49' ||  invoiceSort == 'FY64')){
                    var isDirtRecordInvoice = page.getEditBox().getExtField("isDirtRecordInvoice").getValue();
                    if(isEmpty(isDirtRecordInvoice)) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530 || "提示", "请填写智能船舶项目费用！");
                        return false;
                    }
                }

                //订单号存在时，根据签收单号获取具体的订单金额
                if(innerOrder && companyCode.substring(0,2)=='68'){
                    var signNo = page.getEditBox().getExtField('signNo').getValue();
                    var msg = "";
                    var feeInvoiceId = isCreate ? null : currentRecord.feeInvoiceId;
                    C.syncRequest.callAction('getOrderFeeBySignNo','validateInvoiceAndOrder',{signNo:signNo,innerOrder:innerOrder,vesselCode:vesselCode,invoiceNo:invoiceNo,feeInvoiceId:feeInvoiceId},function(a,d,resp){
                        if(resp.success && resp.extend){
                            var cnyFee = resp.extend.cnyFee;
                            var sumTotalAmount = resp.extend.sumTotalAmount;
                            var exchangeRate = resp.extend.exchangeRate;
                            var equipBillCurrency = resp.extend.equipBillCurrency;
                            page.getEditBox().getExtField('equipBillQuote').setValue(cnyFee)
                            page.getEditBox().getExtField('equipBillCurrency').setValue(equipBillCurrency)
                        }
                    });
                    if(msg){
                        Ext.MessageBox.alert("信息",msg);
                        return
                    }
                }

                return true;
            });
            //针对客运且费用类别是FY01的必输项判断
            function verifyIsNullKeFY01(fy01Map,num){
                if(isEmpty(fy01Map.get("invoiceNo"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_138770||"发票号不能为空",function(){
                            page.getEditBox().getExtField('invoiceNo').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237990||"记录中存在发票号为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("invoiceDate"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238190||"发票日期不能为空",function(){
                            page.getEditBox().getExtField('invoiceDate').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238180||"记录中存在发票日期为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("amountWithoutTax"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238170||"不含税总金额不能为空",function(){
                            page.getEditBox().getExtField('amountWithoutTax').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238160||"记录中存在不含税总金额为空,请维护");
                        return false;
                    }
                }

                if(isEmpty(fy01Map.get("taxAmount"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238130||"发票总税额不能为空",function(){
                            page.getEditBox().getExtField('taxAmount').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238120||"记录中存在发票总税额为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("amount"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238100||"发票总金额不能为空",function(){
                            page.getEditBox().getExtField('amount').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238090||"记录中存在发票总金额为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("dtlAmountWithoutTax"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238070||"不含税金额不能为空",function(){
                            page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237980||"记录中存在不含税金额为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("dtlTaxAmount"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237960||"税额不能为空",function(){
                            page.getEditBox().getExtField('dtlTaxAmount').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237950||"记录中存在税额为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("dtlAmount"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237930||"含税金额不能为空",function(){
                            page.getEditBox().getExtField('dtlAmount').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237910||"记录中存在含税金额为空,请维护");
                        return false;
                    }
                }
                if(isEmpty(fy01Map.get("baseAmount"))){
                    if(isEmpty(num)){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237900||"人民币金额不能为空",function(){
                            page.getEditBox().getExtField('baseAmount').focus();
                        });
                        return false;
                    }else{
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_237880||"记录中存在人民币金额为空,请维护");
                        return false;
                    }
                }
                return true;
            }
            //针对客运且费用类别是FY01的金额判断
            function verifyAmountKeFY01(){
                //验证发票金额
                var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                var taxAmount = Number(page.getEditBox().getValue('taxAmount'));
                var amount = Number(page.getEditBox().getValue('amount'));
                var taxRate = Number(page.getEditBox().getValue('taxRate'));
                //发票总税额根据税率计算值的1%上下浮动
                var taxAmountMax = amountWithoutTax * (taxRate + 0.01)
                var taxAmountMin = amountWithoutTax * (taxRate - 0.01)
                if (( !isEmpty(page.getEditBox().getValue('amountWithoutTax'))||!isEmpty(page.getEditBox().getValue('taxAmount')) )&&
                        amountWithoutTax==0&&taxAmount==0) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140500||"发票不含税总金额和发票总税额不能都等于零",function(){
                        page.getEditBox().getExtField('amountWithoutTax').focus();
                    });
                    return false;
                }
                if(taxRate != 0) {
                    if(Math.abs(taxAmount) > Math.abs(taxAmountMax) || Math.abs(taxAmount) < Math.abs(taxAmountMin) ) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238040||"发票总税额超过了根据税率计算值的1%，请检查并修改！",function(){
                            page.getEditBox().getExtField('taxAmount').focus();
                        });
                        return false;
                    }
                } else {
                    if(taxAmount != 0 ) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238030||"当前记录的税率为0,发票总税额不等于0，请检查并修改！",function(){
                            page.getEditBox().getExtField('taxAmount').focus();
                        });
                        return false;
                    }
                }
                if (amount != (amountWithoutTax + taxAmount).toFixed(2)) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236920||"发票不含税总金额 加 发票总税额 不等于 发票总金额",function(){
                        page.getEditBox().getExtField('amountWithoutTax').focus();
                    });
                    return false;
                }
                //验证明细金额
                var dtlAmount = Number(page.getEditBox().getValue('dtlAmount'));
                var dtlAmountWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                var dtlTaxAmount = Number(page.getEditBox().getValue('dtlTaxAmount'));
                //税额根据税率计算值的1%上下浮动
                var dtlTaxAmountMax = dtlAmountWithoutTax * (taxRate + 0.01)
                var dtlTaxAmountMin = dtlAmountWithoutTax * (taxRate - 0.01)
                if (( !isEmpty(page.getEditBox().getValue('dtlAmountWithoutTax'))||!isEmpty(page.getEditBox().getValue('dtlTaxAmount')) )&&
                        dtlAmountWithoutTax==0&&dtlTaxAmount==0) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_140510||"不含税金额和税额不能都等于零",function(){
                        page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                    });
                    return false;
                }
                if(taxRate != 0) {
                    if(Math.abs(dtlTaxAmount) > Math.abs(dtlTaxAmountMax) || Math.abs(dtlTaxAmount) < Math.abs(dtlTaxAmountMin) ) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238010||"税额超过了根据税率计算值的1%，请检查并修改！",function(){
                            page.getEditBox().getExtField('dtlTaxAmount').focus();
                        });
                        return false;
                    }
                } else {
                    if(dtlTaxAmount !=  0) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_238000||"当前记录的税率为0,税额不等于0，请检查并修改！",function(){
                            page.getEditBox().getExtField('dtlTaxAmount').focus();
                        });
                        return false;
                    }
                }
                if (dtlAmount != (dtlAmountWithoutTax + dtlTaxAmount).toFixed(2)) {
                    Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示",CSIS.Lang.ID_236940||"不含税金额 加 税额 不等于 含税金额",function(){
                        page.getEditBox().getExtField('dtlAmountWithoutTax').focus();
                    });
                    return false;
                }
                return true;
            }
            page.getToolbarBox().addListener('save',function(){
                isNeedChange = false;
                listenerFlag = 0;
                page.getEditBox().setBoxReadOnly(true);
                page.getToolbarBox().setAllButtonsStatus(C.ToolBarStatus.VIEW);
                setButtonStatus('create',true)
                setButtonStatus('edit',true)
                setButtonStatus('remove',true)
                changeInvoiceNoCount = 0;
                if(!isEmpty(companyCode)&&youlunFlag){
                    changeInvoiceNoCount = 1;
                }
                if(rollbackUpdateFlag){
                    rollbackUpdateFlag = false;
                    setButtonStatus('create',true);
                    rebackUpdateBtn.enable();
                    commonListener(currentRecord);
                }else{
                    set3ButtonStatus(true);
                }
            });
            page.getToolbarBox().addListener('cancel',function(){
                isNeedChange = false;
                var eb = page.getEditBox();
                setComboGrid(eb);
                page.getEditBox().setBoxReadOnly(true);
                setButtonStatus('create',true)
                //根据CurrentRecord来判断按钮状态yangxl 20180327
                currentRecord = page.getGridBox().getSelectedRecord()
                if(currentRecord){
                    btnStatusByCurrentRecord(currentRecord)
                }else{
                    ////修正新增后直接取消时，编辑和删除按钮变亮/////
                    page.getToolbarBox().getButton('edit').setDisabled(true)
                    page.getToolbarBox().getButton('remove').setDisabled(true)
                    if(page.getGridBox().getSelectedRecord()){
                        setButtonStatus('edit',true)
                        setButtonStatus('remove',true)
                    }
                    set3ButtonStatus(true);
                }
                changeInvoiceNoCount = 0;
                if(!isEmpty(companyCode)&&youlunFlag){
                    changeInvoiceNoCount = 1;
                }
                isCreate =false; isEdit = false; listenerFlag = 0;
                if(rollbackUpdateFlag){ rollbackUpdateFlag = false; rebackUpdateBtn.enable(); }
                billNoFlag = false; scanBtn.disable();
            });
            page.getToolbarBox().addListener('reset',function(){
                if(page.getEditBox().getValue("vesselCode").length>0) setComboGrid(page.getEditBox());
            });
            page.getToolbarBox().addListener('delete', function () {
                var record = page.getGridBox().getSelectedRecord();
                if(record && !isEmpty(record.bmsId)){
                    showRemoveWindow();
                    return true;
                }
            });
            function showRemoveWindow() {
                var window = Ext.create('Ext.window.Window', {
                    width: 500,
                    height: 250,
                    layout: 'border',
                    title: "BMS平台发票退回原因",
                    modal: true,
                    items: [{
                        xtype: 'form',
                        region: 'center',
                        frame: true,
                        layout: {
                            type: 'column',
                            align: 'stretch'
                        },
                        defaults: {
                            labelSeparator: "：",
                            labelWidth: 70,
                            height: 10,
                            width: 470,
                            labelAlign: "left"
                        },
                        items: [
                            {
                                xtype: 'textarea',
                                id: 'suggest',
                                name: 'suggest',
                                fieldLabel: '退回原因<font color="red">*</font>',
                                height: 100,

                            }
                        ]
                    }],
                    buttons: [
                        {
                            text: "确定",
                            handler: function () {
                                var form = this.up("window").down("form");
                                var suggest = form.getValues()["suggest"];
                                if (suggest == "") {
                                    Ext.MessageBox.alert("提示", "退回意见不能为空");
                                    return
                                }
                                var receiveMask1 = new Ext.LoadMask(window, {msg: "正在处理，请稍候..."});
                                receiveMask1.show();

                                var record = page.getGridBox().getSelectedRecord();
                                record.bmsDelReason = suggest;
                                C.syncRequest.callAction('update', 'feeInvoice', record,
                                    function (action, domainName, resp) {
                                        window.close();
                                        receiveMask1.hide();
                                    }
                                )
                            }
                        },
                        {
                            text: '取消',
                            handler: function () {
                                window.close()
                            }
                        }
                    ]
                });
                window.show()
            }
            //控制主表tab页才能使用工具条
            page.getEditBox().getEditArea().getUI().addListener('tabchange', function(tabPanel, newCard, oldCard) {
                if(oldCard.title == (CSIS.Lang.ID_112770||'发票信息'))page.getToolbarBox().getUI().hide();
                if(newCard.title == (CSIS.Lang.ID_112770||'发票信息'))page.getToolbarBox().getUI().show();
                if (newCard.title == '关联港使费附件') {
                    refreshAccessories();
                }
            });
            if(youlunFlag&&companyCode.substring(0,4)!='0811'&&companyCode.substring(0,4)!='1331'){
                page.getEditBox().getExtField('isAdvanceFee').addListener('change', function(src,event, record, index){
                    var invoiceSortDetail = page.getEditBox().getExtField('invoiceSortDetail').getValue();
                    if(invoiceSortDetail=='FY01001'){
                        if(src.value=='1')setBoxReadOnlyEx(page.getEditBox(), false, 'invoiceNo,invoiceDate,invoiceCode');
                        else setBoxReadOnlyEx(page.getEditBox(), true, 'invoiceNo,invoiceDate,invoiceCode');
                    }
                });  }
            // 针对油运  检验费 油公司检验费 只允许陈贵+张林红编辑权限
            page.getEditBox().getExtField('invoiceSortDetail').addListener('change',function(src){
                if(isCreate){
                    var invoiceSortDetail=   page.getEditBox().getExtField('invoiceSortDetail').getComboValue().display;
                    if((!daYuanFlag&&!companyCode.startWith("1331")&&!companyCode.startWith("6207")&&!companyCode.startWith("0811"))&&(CSIS.Lang.ID_140440||"油公司检验费")==invoiceSortDetail&&IsYYfee==false){
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',"针对油轮公司费用科目为油公司检验费的数据，只有辛钢、张欣、王洪波可以操作！");
                    } }
            });
            function setFieldDisabledCommon(){
                var ifCanUseTax = page.getEditBox().getValue('ifCanUseTax');
                var currency = page.getEditBox().getValue('currency');
                var invoiceSortDetailValue=   page.getEditBox().getExtField('invoiceSortDetail').getValue();
                var invoiceSortValue=   page.getEditBox().getExtField('invoiceSort').getValue();
                if(youlunFlag &&!isEmpty(currency)&& currency!='CNY'&&(ifCanUseTax=='1'||ifCanUseTax=='5'||ifCanUseTax=='6')){
                    Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',CSIS.Lang.ID_140540||"非人民币不能勾选包含增值税!");
                    page.getEditBox().getExtField("ifCanUseTax").setValue("0");
                    return false;
                }
                if(ifCanUseTax=="1"||ifCanUseTax=='5'||ifCanUseTax=='6'){
                    page.getEditBox().getExtField("dtlTaxAmount").setDisabled(false);
                    page.getEditBox().getExtField("taxRate").setDisabled(false);
                    if(youlunFlag){
                        setSafeFlag();
                        page.getEditBox().getExtField("taxAmount").setDisabled(false);
                    }
                    if(haiteFlag) page.getEditBox().getExtField("taxRate").setDisabled(false);
                    if (companyCode.startsWith('91')) {
                        page.getEditBox().getExtField("taxAmount").setDisabled(false);
                        page.getEditBox().getExtField("dtlTaxAmount").setDisabled(false);
                        page.getEditBox().getExtField("taxRate").setDisabled(false);
                    }
                }else{
                    page.getEditBox().getExtField("dtlTaxAmount").setDisabled(true);
                    if(isWlOrderCreate||isBjOrderCreate){
                        page.getEditBox().getExtField("taxRate").setDisabled(false);
                    }
                    if(youlunFlag){
                        page.getEditBox().getExtField("taxAmount").setDisabled(true);
                        page.getEditBox().getExtField("taxRate").setDisabled(true);
                        page.getEditBox().setValue('safeFlag',false);
                    }
                    page.getEditBox().setValue("taxAmount",0);
                    page.getEditBox().setValue("dtlTaxAmount",0);
                    page.getEditBox().getExtField("taxRate").setValue("0");
                    if (companyCode.startsWith('91')) {
                        page.getEditBox().getExtField("taxAmount").setDisabled(true);
                        page.getEditBox().getExtField("dtlTaxAmount").setDisabled(true);
                        page.getEditBox().getExtField("taxRate").setDisabled(true);
                    }
                    tempFields.put("taxRateName","0")
                }
            }
            //选择船舶时船舶对应的公司代码不为1193，就把税率设成0
            page.getEditBox().getExtField('vesselCode').addListener('change', function (e, t, eOpts) {
                //油运公司才用这个功能
                if(isEmpty(companyCode) || !youlunFlag) return;
                if(!isNeedChange) return;
                C.ajax.callAction("checkSapCode","feeInvoice",{vesselCode: e.value},
                        function(action,domain,resp){
                            if(resp.success){
                                page.getEditBox().getExtField("taxRate").setValue("0");
                                page.getEditBox().getExtField("ifCanUseTax").setValue("2");
                            }
                        })
            });
            //给费用科目和付款单位加上监听，根据费用科目和付款单位到所属组织表查找是否属安全费并且赋值
            function setSafeFlag(){
                if(youlunFlag){
                    var invoiceSortDetail = page.getEditBox().getValue('invoiceSortDetail');
                    var invoiceSort = page.getEditBox().getValue('invoiceSort');
                    var ifCanUseTax  = page.getEditBox().getValue('ifCanUseTax');var vesselCode  = page.getEditBox().getValue('vesselCode');
                    if( (invoiceSortDetail=='FY01002'||invoiceSortDetail=='FY01007'||invoiceSortDetail=='FY01004'||
                            invoiceSortDetail=='FY43001'||invoiceSortDetail=='FY43002'||invoiceSortDetail=='FY13010'||invoiceSortDetail=='FY13011'||invoiceSortDetail=='FY13012'
                            ||invoiceSortDetail=='FY69004'||invoiceSort=='FY19')){
                        var vesselNationality = "";
                        if (!isEmpty(vesselCode)) {
                            C.syncRequest.callAction("getVesselNationality", 'vessel', {vesselCode: vesselCode}, function (actionName, domainName, resp) {
                                if (resp != null) {
                                    vesselNationality = resp.msg;
                                }
                            });
                        }
                        if(vesselNationality=='CN')page.getEditBox().getExtField("safeFlag").setValue(true);
                    }else{
                        page.getEditBox().getExtField("safeFlag").setValue(false);
                    }
                }
            }
            page.getEditBox().getExtField('invoiceSortDetail').addListener('change', function (e, t, eOpts) { //能源公司才用这个功能
                if(isEmpty(companyCode) || !youlunFlag) return;
                if(!isNeedChange) return;
                setSafeFlag();
            });
            page.getEditBox().getExtField('invoiceSort').addListener('change', function (e, t, eOpts) { //能源公司才用这个功能
                setSafeFlag();
            });

            //发票总金额监听
            page.getEditBox().getExtField('amount').addListener('blur', function (e, t, eOpts) {
                if(!isNeedChange) return;
                diffTailFlag = true;
                var amount = Number(page.getEditBox().getExtField("amount").getValue());  //发票总金额
                var oldAmountWithoutTax = Number(page.getEditBox().getExtField("amountWithoutTax").getValue());  //原发票不含税金额
                var oldTaxAmount = Number(page.getEditBox().getExtField("taxAmount").getValue());  //原发票总金额
                var taxRate = Number(page.getEditBox().getValue('taxRate'));//税率
                var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                var taxAmount = Number(page.getEditBox().getValue('taxAmount'));
                if (amountWithoutTax == 0 || Math.abs((accAdd(oldAmountWithoutTax,oldTaxAmount)-amount))/amount>0.01) {//调整金额与原金额差额较多重新计算不含税金额
                    // 发票总税额=（发票总金额/(1+税率)）*税率，发票总税额保留2位小数  不含税总金额=发票总金额-发票总税额
                    taxAmount =  accMul((accDiv(amount,(1+taxRate))),taxRate).toFixed(2);   //发票总税额
                    amountWithoutTax = amount - taxAmount;
                    page.getEditBox().getExtField("amountWithoutTax").setValue(amountWithoutTax);
                    page.getEditBox().getExtField("taxAmount").setValue(taxAmount);
                } else {
                    taxAmount = Number(amount-amountWithoutTax).toFixed(2);
                    page.getEditBox().getExtField("taxAmount").setValue(taxAmount);
                    page.getEditBox().getExtField("taxRate").setValue((accDiv(taxAmount, amountWithoutTax).toFixed(2)));
                }
                var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                page.getEditBox().getExtField("dtlAmountWithoutTax").setValue(amountWithoutTax);
                page.getEditBox().getExtField("dtlTaxAmount").setValue(taxAmount);
                page.getEditBox().getExtField("dtlAmount").setValue(amount);
            });
            //含税金额 （元）的监听
            page.getEditBox().getExtField('dtlAmount').addListener('blur', function (e, t, eOpts) {
                if(!isNeedChange) return;
                diffTailFlag = true;
                var editBox = page.getEditBox();
                var dtlAmount = Number(editBox.getValue('dtlAmount'));
                var dtlAmountWithoutTax = Number(editBox.getValue('dtlAmountWithoutTax'));
                var dtlTaxAmount = Number(editBox.getValue('dtlTaxAmount'));
                var taxRate = Number(editBox.getValue('taxRate'));//税率
                var exchangeRate = Number(editBox.getValue('exchangeRate'));
                if (dtlAmountWithoutTax == 0 || Math.abs((accAdd(dtlTaxAmount,dtlAmountWithoutTax)-dtlAmount))/dtlAmount>0.01) {
                    // 发票税额=（发票金额/(1+税率)）*税率，发票税额保留2位小数  不含金额=发票总金额-发票税额
                    dtlTaxAmount = accMul((accDiv(dtlAmount,(1+taxRate))),taxRate).toFixed(2);//计算不含税金额
                    if(taxRate==0){
                        dtlAmountWithoutTax=dtlAmount;
                        dtlTaxAmount =  dtlAmount - dtlAmountWithoutTax;
                    }else{
                        dtlAmountWithoutTax =  dtlAmount - dtlTaxAmount;
                    }
                    editBox.getExtField("dtlAmountWithoutTax").setValue(dtlAmountWithoutTax);
                    editBox.getExtField("dtlTaxAmount").setValue(dtlTaxAmount);
                } else {
                    editBox.getExtField("dtlTaxAmount").setValue(dtlAmount-dtlAmountWithoutTax);
                }
                editBox.setValue('baseAmount', dtlAmount * exchangeRate);
                var isFreight = page.getEditBox().getValue('isFreight');
                if(youlunFlag&&isFreight) {page.getEditBox().setValue('miscAmount',dtlAmount)}
            });

            page.getEditBox().getExtField('dtlAmount').addListener('change', function (e, t, eOpts) {
                if(!isNeedChange) return;
                var editBox = page.getEditBox();
                var dtlAmount = Number(editBox.getValue('dtlAmount'));
                var exchangeRate = Number(editBox.getValue('exchangeRate'));
                editBox.setValue('baseAmount', dtlAmount * exchangeRate);
            });

            //修改发票不含税金额，触发修改发票税额，触发修改不含税金额
            page.getEditBox().getExtField('amountWithoutTax').addListener('change', function (e, t, eOpts) {
                if (isNeedChange ) {
                    //发票总金额、发票总税额、发票不含税总金额
                    var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                    var amount = Number(page.getEditBox().getValue('amount'));
                    if (!diffTailFlag) {
                        var taxRate = 0;
                        if(page.getEditBox().getValue('taxRate')!='null'){
                            taxRate = Number(page.getEditBox().getValue('taxRate'));
                        }
                        var taxAmount = accMul(amountWithoutTax,taxRate).toFixed(2);
                        page.getEditBox().setValue('taxAmount', taxAmount);
                        var amount = accAdd(amountWithoutTax,taxAmount);
                        page.getEditBox().setValue('amount', amount);
                    }
                    page.getEditBox().getExtField("dtlAmountWithoutTax").setValue(amountWithoutTax);
                    diffTailFlag= false;
                }
            });
            //修改发票税额,可能触发修改税额
            var diffTailFlag = false;
            page.getEditBox().getExtField('taxAmount').addListener('blur', function (e, t, eOpts) {
                if (isNeedChange ) {
                    var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                    var taxAmount = Number(page.getEditBox().getValue('taxAmount'));
                    var amount = Number(page.getEditBox().getValue('amount'));
                    var taxRate = Number(page.getEditBox().getValue('taxRate'));
                    if (amount > 0) {
                        diffTailFlag = true;
                        amountWithoutTax = Number(amount - taxAmount).toFixed(2);
                        page.getEditBox().getExtField("amountWithoutTax").setValue(amountWithoutTax);
                        if(taxRate<=0){
                            page.getEditBox().getExtField("taxRate").setValue((accDiv(taxAmount, amountWithoutTax).toFixed(2)));
                        }
                    } else {
                        var taxRate = Number(page.getEditBox().getValue('taxRate'));//税率
                        amountWithoutTax = accDiv(taxAmount,taxRate).toFixed(2);
                        amount = accAdd(amountWithoutTax,taxAmount);
                        page.getEditBox().setValue('amount', amount);
                        page.getEditBox().setValue('amountWithoutTax', amountWithoutTax);
                    }
                }
            });
            //修改不含税金额，触发修改税额change
            page.getEditBox().getExtField('dtlAmountWithoutTax').addListener('change', function (e, t, eOpts) {
                if (isNeedChange) {
                    var taxRate = 0;
                    if(page.getEditBox().getValue('taxRate')!='null'){
                        taxRate = Number(page.getEditBox().getValue('taxRate'));
                    }
                    if (!diffTailFlag) {
                        var dtlAmountWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var dtlTaxAmount = accMul(dtlAmountWithoutTax,taxRate);
                        //解决税额不变的bug
                        var dtlWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                        var dtlAmount = (dtlWithoutTax + dtlTaxAmount).toFixed(2);
                        page.getEditBox().setValue('dtlAmount', dtlAmount);
                        page.getEditBox().setValue('dtlTaxAmount', dtlTaxAmount);
                        page.getEditBox().setValue('baseAmount', accMul(dtlAmount,exchangeRate));
                    } else{
                        var dtlAmount = Number(page.getEditBox().getValue('dtlAmount'));
                        var dtlWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var dtlTaxAmount = (dtlAmount - dtlWithoutTax).toFixed(2);
                        page.getEditBox().setValue('dtlTaxAmount', dtlTaxAmount);
                    }
                    diffTailFlag= false;
                }
            });
            //修改税额,不会触发其他change
            page.getEditBox().getExtField('dtlTaxAmount').addListener('blur', function (e, t, eOpts) {
                if (isNeedChange) {
                    var dtlAmount = Number(page.getEditBox().getValue('dtlAmount'));
                    var dtlTaxAmount = Number(page.getEditBox().getValue('dtlTaxAmount'));
                    if (dtlAmount > 0) {
                        diffTailFlag = true;
                        page.getEditBox().setValue('dtlAmountWithoutTax', dtlAmount-dtlTaxAmount);
                    }else {
                        var dtlWithoutTax = Number(page.getEditBox().getValue('dtlAmountWithoutTax'));
                        var dtlTaxAmount = Number(page.getEditBox().getValue('dtlTaxAmount'));
                        var exchangeRate = Number(page.getEditBox().getValue('exchangeRate'));
                        var dtlAmount = (dtlWithoutTax + dtlTaxAmount).toFixed(2);
                        page.getEditBox().setValue('dtlAmount', dtlAmount);
                        page.getEditBox().setValue('baseAmount', accMul(dtlAmount,exchangeRate));
                    }
                }
            });
            //大远人民币折算金额
            if(page.getEditBox().getExtField('equipBillQuote') && companyCode.substring(0,2)!='68'){
                page.getEditBox().getExtField('equipBillQuote').addListener('change', function (e, t, eOpts) {
                    if (isNeedChange) {
                        var equipBillRate = 0;
                        if (page.getEditBox().getValue('equipBillRate') != 'null') {
                            equipBillRate = Number(page.getEditBox().getValue('equipBillRate'));
                        }
                        var equipBillQuote = Number(page.getEditBox().getValue('equipBillQuote'));
                        page.getEditBox().setValue('equipBillRmb', accMul(equipBillQuote, equipBillRate));
                    }
                });
            }
            if(page.getEditBox().getExtField('equipBillRate')){
                page.getEditBox().getExtField('equipBillRate').addListener('change', function (e, t, eOpts) {
                    var equipBillRate = Number(page.getEditBox().getValue('equipBillRate'));
                    var equipBillQuote = Number(page.getEditBox().getValue('equipBillQuote'));
                    page.getEditBox().setValue('equipBillRmb', accMul(equipBillRate,equipBillQuote));
                });
            }
            if(page.getEditBox().getExtField('equipBillRmb')){
                page.getEditBox().getExtField('equipBillRmb').addListener('change', function (e, t, eOpts) {
                    var auditTaxRate = 0;
                    if (page.getEditBox().getValue('dyTaxRate') != 'null') {
                        auditTaxRate = Number(page.getEditBox().getValue('dyTaxRate'));
                    }
                    var auditFee = Number(page.getEditBox().getValue('equipBillRmb'));
                    page.getEditBox().setValue('dyAmount',accAdd(accMul(auditFee, auditTaxRate),auditFee));
                });
            }
            if(page.getEditBox().getExtField('dyTaxRate')){
                page.getEditBox().getExtField('dyTaxRate').addListener('change', function (e, t, eOpts) {
                    var auditTaxRate = Number(page.getEditBox().getValue('dyTaxRate'));
                    var auditFee = Number(page.getEditBox().getValue('equipBillRmb'));
                    page.getEditBox().setValue('dyAmount',accAdd(accMul(auditFee, auditTaxRate),auditFee));
                });
            }

            page.getEditBox().getExtField('currency').addListener('change', function (e, t, eOpts) {
                var currency = page.getEditBox().getValue('currency');
                //问题 -查看非当前月份外币发票，加载币种触发该事件导致汇率与录入汇率不一致(当前月份汇率与录入发票时汇率)，加判断非增加编辑不触发change事件
                if(isNeedChange){
                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:currency,currencyTo:'CNY'},
                            function(action,domainName,resp){
                                page.getEditBox().setValue('exchangeRate',resp);
                            });

                    if(currency != 'CNY'){
                        page.getEditBox().getExtField('taxRate').setValue(0);
                        page.getEditBox().setReadOnly('taxRate', true);
                    } else {
                        page.getEditBox().getExtField('taxRate').setValue(0.13);
                        page.getEditBox().setReadOnly('taxRate', false);
                    }
                }
            });
            //修改汇率，不会触发其他change
            page.getEditBox().getExtField('exchangeRate').addListener('change', function (e, t, eOpts) {
                var exchangeRate = page.getEditBox().getValue('exchangeRate');
                var dtlAmount = page.getEditBox().getValue('dtlAmount');
                page.getEditBox().setValue('baseAmount', accMul(exchangeRate,dtlAmount));
            });
            if(!isEmpty(companyCode)&&companyCode.startWith('68')){
                page.getEditBox().getExtField('maintainPrimerQty').addListener('change', function (e, t, eOpts) {
                    maintainTotalAmount()
                });
                page.getEditBox().getExtField('maintainOtherQty').addListener('change', function (e, t, eOpts) {
                    maintainTotalAmount()
                });
                page.getEditBox().getExtField('dockSelfPolishingQty').addListener('change', function (e, t, eOpts) {
                    dockTotalAmount()
                });
                page.getEditBox().getExtField('dockOtherQty').addListener('change', function (e, t, eOpts) {
                    dockTotalAmount()
                });
            }
            function maintainTotalAmount(btnStatus,maintainPrimerQty,maintainOtherQty){
                if(btnStatus=="rowselected"){
                    var maintainPrimerQty = maintainPrimerQty?maintainPrimerQty:0
                    var maintainOtherQty = maintainOtherQty?maintainOtherQty:0
                    page.getEditBox().setValue('dockOrMaintainTotalAmount', accAdd(maintainPrimerQty,maintainOtherQty));
                    return
                }
                var maintainPrimerQty = page.getEditBox().getValue('maintainPrimerQty');
                var maintainOtherQty = page.getEditBox().getValue('maintainOtherQty');
                maintainPrimerQty = maintainPrimerQty?maintainPrimerQty:0
                maintainOtherQty = maintainOtherQty?maintainOtherQty:0
                page.getEditBox().setValue('dockOrMaintainTotalAmount', accAdd(maintainPrimerQty,maintainOtherQty));
            }
            function dockTotalAmount(btnStatus,dockSelfPolishingQty,dockOtherQty){
                if(btnStatus=="rowselected"){
                    var dockSelfPolishingQty = dockSelfPolishingQty?dockSelfPolishingQty:0
                    var dockOtherQty = dockOtherQty?dockOtherQty:0
                    page.getEditBox().setValue('dockOrMaintainTotalAmount', accAdd(dockSelfPolishingQty,dockOtherQty));
                    return
                }
                var dockSelfPolishingQty = page.getEditBox().getValue('dockSelfPolishingQty');
                var dockOtherQty = page.getEditBox().getValue('dockOtherQty');
                dockSelfPolishingQty = dockSelfPolishingQty?dockSelfPolishingQty:0
                dockOtherQty = dockOtherQty?dockOtherQty:0
                page.getEditBox().setValue('dockOrMaintainTotalAmount', accAdd(dockSelfPolishingQty,dockOtherQty));
            }
            var changeInvoiceNoCount = 0;
            if(!isEmpty(companyCode)&&youlunFlag){changeInvoiceNoCount = 1;}
            page.getEditBox().getExtField('invoiceNo').addListener('change', function (e, t, eOpts) {
                if (isCreate) {
                    if(!isEmpty(companyCode)&&companyCode.substring(0,2)!='68'){
                        page.getEditBox().setValue('dtlAmount', 0);
                        page.getEditBox().setValue('dtlAmountWithoutTax', 0);//不含税金额
                        page.getEditBox().setValue('dtlTaxAmount', 0);   //税额
                        page.getEditBox().setValue('amount', 0);     //发票总金额
                        page.getEditBox().setValue('amountWithoutTax', 0);    //发票不含税金额
                        page.getEditBox().setValue('taxAmount', 0);        //发票总税额
                        page.getEditBox().setValue('baseAmount', 0);  //人民币金额
                        if(!youlunFlag){page.getEditBox().setValue('safeFlag', false);}  //是否属安全费
                        changeInvoiceNoCount++;
                    }
                }

                if(companyCode.startWith("080111")){
                    var invoiceNo = page.getEditBox().getExtField("invoiceNo").rawValue;
                    if(currentRecord!=null && invoiceNo!=currentRecord.invoiceNo){
                        page.getEditBox().setValue('isDirtRecordInvoice', '');  //修改了发票号，智能船舶项目费用清空
                    }
                }
            });
            page.getEditBox().getExtField('ifCanUseTax').addListener('change', function(src,event, record, index){
                setFieldDisabledCommon();
            });
            page.getEditBox().getExtField('safeFlag').addListener('change', function(src,event, record, index){  //是否属安全费
                var safeFlag = page.getEditBox().getValue('safeFlag');
                if(!isEmpty(companyCode)&&companyCode.substring(0,4)=='6600'){
                    if(safeFlag=='1'){ //当“是否属安全费”打钩时，“安全费类别”请自动选择为“安全运维费”。
                        page.getEditBox().setValue("safeItem","AQYW");
                    }else{
                        page.getEditBox().setValue("safeItem","");
                    }
                }
            });
            var isAmountFirst = false;
            if(!isEmpty(companyCode)&&youlunFlag){
                page.getEditBox().getExtField('isAmountFirst').addListener('change', function(src,event, record, index){
                    if(!isNeedChange) return;
                    isAmountFirst = page.getEditBox().getValue('isAmountFirst');
                    if(isAmountFirst) {
                        page.getEditBox().setValue('dtlAmount', 0);
                        page.getEditBox().setValue('dtlTaxAmount', 0);
                        page.getEditBox().setValue('dtlAmountWithoutTax', 0);
                        page.getEditBox().setValue('baseAmount', 0);
                        page.getEditBox().getExtField('dtlTaxAmount').setDisabled(true);
                        page.getEditBox().getExtField('dtlAmountWithoutTax').setDisabled(true);
                    }else{
                        page.getEditBox().getExtField('dtlTaxAmount').setDisabled(false);
                        page.getEditBox().getExtField('dtlAmountWithoutTax').setDisabled(false);
                    }
                });
                function setFreight(){
                    var isFreight = page.getEditBox().getValue('isFreight');
                    if(isFreight) {
                        if(youlunFlag){ page.getEditBox().setValue('remark','运费');var dtlAmount =page.getEditBox().getValue('dtlAmount')
                            page.getEditBox().setValue('miscAmount',dtlAmount);setBoxReadOnlyEx(page.getEditBox(), true, 'miscAmount,remark');
                        }else{
                            page.getEditBox().setValue('invoiceDesc','运费');
                            page.getEditBox().getExtField('invoiceDesc').setDisabled(true);
                        }
                    }else{
                        if(youlunFlag){page.getEditBox().setValue('remark','');page.getEditBox().setValue('miscAmount','');setBoxReadOnlyEx(page.getEditBox(), false, 'remark,miscAmount');
                        }else{
                            page.getEditBox().setValue('invoiceDesc',''); page.getEditBox().getExtField('invoiceDesc').setDisabled(false); page.getEditBox().getExtField('invoiceDesc').focus();
                        }
                    }
                }
                page.getEditBox().getExtField('isFreight').addListener('change', function(src,event, record, index){
                    if(!isNeedChange) return;
                    var ifCanUseTax = page.getEditBox().getValue('ifCanUseTax');  //
                    var isFreight = page.getEditBox().getValue('isFreight');
                    setFreight();
                    if(isFreight) {
                        if(ifCanUseTax!="1") return;
                        page.getEditBox().setValue("taxRate",'0.06');
                        tempFields.put("taxRateName",'6%');
                    }else{
                        if(ifCanUseTax=="1"||ifCanUseTax=='5'){
                            page.getEditBox().setValue("taxRate",'0.13');
                            tempFields.put("taxRateName",'13%');
                        }
                    }
                });
            }
            //增加时付初始值
            function setCreateDefaultValue(){
                var eb = page.getEditBox();
                eb.getExtField("currency").setComboValue("CNY",CSIS.Lang.ID_111960||"人民币");
                if(eb.getExtField("zfCurrency")!=null) {
                    eb.getExtField("zfCurrency").setComboValue("CNY",CSIS.Lang.ID_111960||"人民币");
                }
                eb.setValue('exchangeRate','1');
                if(eb.getExtField("zfExchangeRate")!=null) {
                    eb.setValue('zfExchangeRate','1');
                }
                eb.setValue('ifCanUseTax',"1");//触发setFieldDisabledCommon()
                eb.setValue('inputDate',new Date());

                if(companyCode.startWith('080111')){
                    if(currentRecord!=null){
                        eb.setValue('foreStatMonth',currentRecord.foreStatMonth);
                    }
                    if(isEmpty(eb.getExtField("foreStatMonth").getValue())){
                        eb.setValue('foreStatMonth',new Date());
                    }
                }else{
                    eb.setValue('foreStatMonth',new Date());
                }

                eb.setValue('inputUser',userName);
                eb.setValue('invoiceStatus',"1");
                tempFields.put('currencyName', CSIS.Lang.ID_111960||"人民币");
                eb.setValue("taxRate",'0.13');
                tempFields.put("taxRateName",'13%');
                if(youlunFlag){
                    eb.setValue('ifCanUseTax',"2");
                }
                //yangxl 2018-10-25 发票录入界面， 68公司不复制新增 2018-11-28 68个别费用类别可复制新增
                if(currentRecord!=null&&(companyCode.substring(0,2)!="68"||(companyCode.startWith("68")&&freightTypeRemarkMap.get(currentRecord.invoiceSort)))){
                    eb.setValue("occurTimeFrom",currentRecord.occurTimeFrom);
                    eb.setValue("invoiceNo",currentRecord.invoiceNo);
                    eb.setValue("invoiceCode",currentRecord.invoiceCode);
                    eb.setValue("invoiceDesc",currentRecord.invoiceDesc);
                    C.ajax.callAction('getCurRate','exchangeRate',{currencyFrom:currentRecord.currency,currencyTo:'CNY'},
                            function(action,domainName,resp){
                                page.getEditBox().setValue('exchangeRate',resp);
                            });
                    eb.setValue("ifCanUseTax",currentRecord.ifCanUseTax);
                    eb.setValue("taxRate",currentRecord.taxRate);
                    eb.setValue("baseAmount",currentRecord.baseAmount);
                    eb.setValue("amountWithoutTax",currentRecord.amountWithoutTax);
                    eb.setValue("taxAmount",currentRecord.taxAmount);
                    eb.setValue("amount",currentRecord.amount);
                    eb.setValue("invoiceDate",currentRecord.invoiceDate);
                    eb.setValue("ifJigai",currentRecord.ifJigai);
                    eb.setValue("safeFlag",currentRecord.safeFlag);
                    eb.setValue("remark",currentRecord.remark);
                    if(!youlunFlag)eb.setValue("innerOrder",currentRecord.innerOrder);
                    eb.setValue("isFixedAsset",currentRecord.isFixedAsset);
                    eb.setValue("feeFlow",currentRecord.feeFlow);
                    //油运公司的是否先输入含税金额要自动带入下一条的新增
                    if(!isEmpty(companyCode)&&youlunFlag){
                        eb.setValue("isAmountFirst",currentRecord.isAmountFirst);//是否
                        if(currentRecord.isAmountFirst) {
                            page.getEditBox().setValue('dtlAmount', 0);
                            page.getEditBox().setValue('dtlTaxAmount', 0);
                            page.getEditBox().setValue('dtlAmountWithoutTax', 0);
                            page.getEditBox().setValue('baseAmount', 0);
                        }
                        eb.setValue("isFreight",currentRecord.isFreight);
                    }else if(companyCode.substring(0,4)=="6600" || companyCode.startWith("080111")|| companyCode.startWith("1331")){
                        eb.setValue("ifJigai","0");  //库存管理
                        eb.setValue("safeFlag","0"); //是否属安全费
                        eb.setValue("billNo","");  //内部订单号
                        eb.setValue("innerOrder","");  //订单号

                        if(companyCode.startWith("080111")){
                            eb.setValue("isDirtRecordInvoice",currentRecord.isDirtRecordInvoice);  //智能船舶项目费用
                        }
                    }
                    setComboGrid(eb);
                    if(youlunFlag){
                        var invoiceSort = currentRecord.invoiceSort;
                        var invoiceSortDetailValue = currentRecord.invoiceSortDetail;
                        var srcOrderType = currentRecord.srcOrderType;
                        eb.setValue("isFixedAsset",false);
                        page.getEditBox().getExtField('portCode').setValue('')
                        page.getEditBox().getExtField('voyageNo').setValue('')
                        if(invoiceSort == 'FY69'&&(invoiceSortDetailValue=='FY69004'||invoiceSortDetailValue=='FY69005') ||invoiceSort == 'FYR1'){
                            page.getEditBox().setReadOnly('portCode', false);
                            page.getEditBox().setReadOnly('voyageNo', false);
                        }else{
                            page.getEditBox().setReadOnly('portCode', true);
                            page.getEditBox().setReadOnly('voyageNo', true);
                        }
                        if(invoiceSortDetailValue=='FY01004'||invoiceSort == 'FY04'||invoiceSortDetailValue=='FY16002'||
                                (invoiceSort == 'FY06'&&(srcOrderType=='1'||srcOrderType=='2'||srcOrderType=='3'||srcOrderType=='13'))){
                            eb.setValue("innerOrder",currentRecord.innerOrder);if(invoiceSort == 'FY06'){eb.setValue("billNo",currentRecord.billNo);}
                        }
                    }
                    tempFields.put('vesselName', currentRecord.vesselName);
                    tempFields.put('departmentName', currentRecord.departmentName);
                    tempFields.put('customerName', currentRecord.customerName);
                    tempFields.put('contractName', currentRecord.contractName);
                    tempFields.put('payeeName', currentRecord.payeeName);
                    tempFields.put('freightName', currentRecord.freightName);
                    tempFields.put('freightTypeName', currentRecord.freightTypeName);
                    tempFields.put('currencyName', currentRecord.currencyName);
                    tempFields.put('usrName', currentRecord.usrName);
                    tempFields.put("taxRateName",currentRecord.taxRateName);
                }
            }

            var operationRelevanceDomain = new C.Domain('vwFmmOperationRelevanceDtl', [
                {name:'operationRelevanceId',type:'string',length:50},
                {name:'paymentNoticeId',type:'string',length:50},
                {name:'feeInvoiceId',type:'string',length:50},
                {name:'vesselCode',display: CSIS.Lang.ID_100430||'船舶代码',type:'string',length:20},
                {name:'vesselName',display: CSIS.Lang.ID_107220||'船舶',type:'string',length:50},
                {name:'relatedId',display: CSIS.Lang.ID_140550||'关联业务模块主键',type:'string',length:50},
                {name:'relatedName',display: CSIS.Lang.ID_109410||'业务类型',type:'string',length:100},
                {name:'currency',display: CSIS.Lang.ID_113170||'币种',type:'string',length:10},
                {name:'invoiceAmount',display: CSIS.Lang.ID_237740||'发票金额(元)',type:'number',length:12},
                {name:'qty',display: CSIS.Lang.ID_111650||'数量',type:'number',length:10,width:40},
                {name:'relatedAmountWithoutTax',display: CSIS.Lang.ID_237730||'业务不含税金额(元)',type:'number',length:12,width:80},
                {name:'relatedAmount',display: CSIS.Lang.ID_237720||'业务含税金额(元)',type:'number',length:12,width:80},
                {name:'taxAmount',display: CSIS.Lang.ID_237710||'业务税额(元)',type:'number',length:12,width:80},
                {name:'invoiceStatus',display: CSIS.Lang.ID_112610||'发票状态',type:'number',length:2},
                {name:'sendStatus',display: CSIS.Lang.ID_107540||'发送状态',type:'string',length:1},
                {name:'parentId',display: CSIS.Lang.ID_140560||'关联业务模块主表主键',type:'string',length:50},
                {name:'seqNo',display: CSIS.Lang.ID_102840||'序号',type:'number',length:4},
                {name:'rate',display: CSIS.Lang.ID_107420||'单价',type:'number',length:10},
                {name:'remark',display: CSIS.Lang.ID_107690||'备注',type:'string',length:300},
                {name:'className',display: CSIS.Lang.ID_117330||'类别',type:'string',width:150},
                {name:'materialNo',display: CSIS.Lang.ID_109580||'编码',type:'string',width:120},
                {name:'materialName',display: CSIS.Lang.ID_169510||'名称',type:'string',width:120},
                {name:'activityDate',display: CSIS.Lang.ID_237700||'入库/完工日期',type:'date',format:'Y-m-d',width:100},
                {name:'supplierName',display: CSIS.Lang.ID_107250||'供应商',type:'string',width:170},
                {name:'currencyName',display: CSIS.Lang.ID_107510||'币种',type:'string',width:60},
                {name:'auditedFlag',display: CSIS.Lang.ID_138710||'审核标记'}
            ],{ grid:'vesselName,relatedName,className,materialNo,materialName,activityDate,supplierName,currencyName,qty,rate,' +
            'relatedAmountWithoutTax,taxAmount,relatedAmount,invoiceAmount,auditedFlag,remark',
                orderBy: 'activityDate desc'
            });
            //页面进来的时候默认加载（关联消息）
            var curDomain = operationRelevanceDomain;
            operationRelevanceDomain.getDataSource().addListener('beforeload',function(store,record){
                record.limit =null;
            });
            vwFmmMtrPurGridDomain.getDataSource().addListener('load',function(store,record,success,etops){
                if(success){
                    var mainSelectedRecord = page.getGridBox().getSelectedRecord();
                    if(record.length == 0 ||  mainSelectedRecord.invoiceStatus == '3'||mainSelectedRecord.invoiceStatus == '4'||mainSelectedRecord.invoiceStatus == '5'){
                        btnRemoveSub.setDisabled(true);
                    }else{
                        btnRemoveSub.setDisabled(false);
                    }
                    if(record.length>0){
                        var qtySum = 0
                        var relatedAmountSum = 0
                        var taxAmountSum = 0
                        Ext.each(record,function(v){
                            qtySum+= v.data.qty==''?0:v.data.qty
                            relatedAmountSum+= v.data.relatedAmount ==''?0:v.data.relatedAmount
                            taxAmountSum+= v.data.taxAmount==''?0:v.data.taxAmount
                        });
                        operationRelevanceDomain.getDataSource().newRecord({currencyName:(CSIS.Lang.ID_140420||'合计：'),qty:qtySum,relatedAmount:Number(relatedAmountSum).toFixed(2) ,
                            taxAmount:Number(taxAmountSum).toFixed(2)});
                    }
                    calOperationCheckAmount();
                }
            });
            vwFmmSpsPurGridDomain.getDataSource().addListener('load',function(store,record,success,etops){
                if(success){
                    var mainSelectedRecord = page.getGridBox().getSelectedRecord();
                    if(record.length == 0 ||  mainSelectedRecord.invoiceStatus == '3'||mainSelectedRecord.invoiceStatus == '4'||mainSelectedRecord.invoiceStatus == '5'){
                        btnRemoveSub.setDisabled(true);
                    }else{
                        btnRemoveSub.setDisabled(false);
                    }
                    if(record.length>0){
                        var qtySum = 0
                        var relatedAmountSum = 0
                        var taxAmountSum = 0
                        Ext.each(record,function(v){
                            qtySum+= v.data.qty==''?0:v.data.qty
                            relatedAmountSum+= v.data.relatedAmount ==''?0:v.data.relatedAmount
                            taxAmountSum+= v.data.taxAmount==''?0:v.data.taxAmount
                        });
                        operationRelevanceDomain.getDataSource().newRecord({currencyName:(CSIS.Lang.ID_140420||'合计：'),qty:qtySum,relatedAmount:Number(relatedAmountSum).toFixed(2) ,
                            taxAmount:Number(taxAmountSum).toFixed(2)});
                    }
                    calOperationCheckAmount();
                }
            });
            //FY69费用类别在TD计算合计避免出错添加金额三字段参与合计
            vwFmmVrmShipGuideQueryDomain2.getDataSource().addListener('load',function(store,record,success,etops){
                if(success){
                    var mainSelectedRecord = page.getGridBox().getSelectedRecord();
                    if(record.length>0){
                        var qtySum = 0
                        var relatedAmountSum = 0
                        var taxAmountSum = 0
                        Ext.each(record,function(v){
                            qtySum+= v.data.qty==''?0:v.data.qty
                            relatedAmountSum+= v.data.relatedAmount ==''?0:v.data.relatedAmount
                            taxAmountSum+= v.data.taxAmount==''?0:v.data.taxAmount
                        });
                        operationRelevanceDomain.getDataSource().newRecord({currencyName:(CSIS.Lang.ID_140420||'合计：'),qty:qtySum,relatedAmount:Number(relatedAmountSum).toFixed(2) ,
                            taxAmount:Number(taxAmountSum).toFixed(2)});
                    }
                    calOperationCheckAmount();
                }
            });
            var grid = new C.GridBox(operationRelevanceDomain, {paging: false,showCheckBox:true, editing: false});
            //发票状态： 3： 未审核  4：已审核  5：已付款   1：新增
            grid.addListener('rowSelected', function(src, event, record){
                if(currentRecord&&currentRecord.invoiceStatus) {
                    if (currentRecord.invoiceStatus == '3' || currentRecord.invoiceStatus == '4' || currentRecord.invoiceStatus == '5' ) {
                        btnRemoveSub.setDisabled(true);
                    } else {
                        btnRemoveSub.setDisabled(false);
                    }
                }else { btnRemoveSub.setDisabled(true);}
            });
            grid.addListener('rowChecked', function(src, event, record){ calOperationCheckAmount();});
            grid.addListener('rowUnChecked', function(src, event, record){ calOperationCheckAmount();});
            var btnRemoveSub = Ext.create('Ext.button.Button',{text: CSIS.Lang.ID_108850||'删除',icon:'../res/img/themes/default/table_delete.png',
                handler: function () {
                    var selectedRecords = grid.getCheckedRecords();
                    if (selectedRecords == null || selectedRecords.length < 1) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_100780||"信息", CSIS.Lang.ID_113790||"请选择一条记录！");
                        return;
                    }else{
                        var operationRelevanceIdArray ="";
                        for(var i=0;i<selectedRecords.length ;i++){
                            var operationRelevanceId =selectedRecords[i].operationRelevanceId;  //关联id
                            operationRelevanceIdArray = operationRelevanceIdArray+operationRelevanceId+",";
                            if(selectedRecords.length == i+1){
                                operationRelevanceIdArray = operationRelevanceIdArray.substr(0,operationRelevanceIdArray.length-1);
                            }
                        }
                        Ext.Msg.confirm(CSIS.Lang.ID_100780||'信息',CSIS.Lang.ID_225400||'确定要删除所选项吗?', function(btn){
                            if(btn=='yes'){
                                C.ajax.callAction('batchRemove','operationRelevance',{id:operationRelevanceIdArray},
                                        function(action,domainName,resp){
                                            isChange = true;
                                            changeGrid(currentRecord);
                                        });
                            }
                        },this);
                    }
                }
            })
            var toolbarSub = Ext.create('Ext.toolbar.Toolbar', {
                items:[btnRemoveSub,{xtype:'textfield',id:"totalWithOutTaxAmount",fieldLabel:CSIS.Lang.ID_110800||'不含税金额',labelAlign : 'right'},
                    {xtype:'textfield',id:"totalTaxAmount",fieldLabel:CSIS.Lang.ID_107610||'税金',labelAlign : 'right'},
                    {xtype:'textfield',id:"totalRmbAmount",fieldLabel:CSIS.Lang.ID_112580||'人民币金额',labelAlign : 'right'}]
            });
            // 不含税金额、税金、人民币金额
            var  calOperationCheckAmount =  function(){
                var relatedAmountWithoutTaxSum = 0;  //不含税金额总和
                var taxAmountSum = 0;   //税金总和
                var cnyFeeSum = 0 ;   //人民币金额总和
                var records = grid.getCheckedRecords();
                if(records.length>0){
                    for(var i=0;i<records.length;i++){
                        if(records[i].relatedId!=null&&records[i].relatedId!=''){
                            relatedAmountWithoutTaxSum += records[i].relatedAmountWithoutTax == '' ? 0 : records[i].relatedAmountWithoutTax
                            taxAmountSum += records[i].taxAmount == '' ? 0 : records[i].taxAmount
                            cnyFeeSum +=records[i].cnyFee == '' ? 0 : records[i].cnyFee
                        }
                    }
                }
                Ext.getCmp("totalWithOutTaxAmount").setValue(relatedAmountWithoutTaxSum);
                Ext.getCmp("totalTaxAmount").setValue(taxAmountSum);
                Ext.getCmp("totalRmbAmount").setValue(cnyFeeSum);
            }
            var tabPanel1 = Ext.create('Ext.panel.Panel', {
                region:'south',
                layout: 'fit',
                split:true,
                height:150,
                items: grid.getUI(),
                title: CSIS.Lang.ID_140030||'关联信息'
            })
            page.getEditBox().getExtField("dtlTaxAmount").setDisabled(true);
            /***附件开始*/
            var attachmentDomain = new CSIS.Domain('attachmentFile', [
                {name: 'attachmentFileId'},
                {name: 'referenceId'},
                {name: 'referenceModule', display: CSIS.Lang.ID_108980||'引用模块'},
                {name: 'attachmentName', display: CSIS.Lang.ID_108990||'附件名称', width: 200},
                {name: 'attachmentFilePath', display: CSIS.Lang.ID_109000||'附件路径'},
                {name: 'createdByUser', display: CSIS.Lang.ID_116390||'上传用户',width: 100},
                {name: 'createdByUserName', display: CSIS.Lang.ID_116390||'上传用户',width: 100},
                {name: 'createdDtmLoc', display: CSIS.Lang.ID_116400||'上传时间',type:'date',format:'Y-m-d'},
                {name: 'remark', display: CSIS.Lang.ID_107690||'备注', width: 250,
                    render: function (v, meta) {
                        meta.tdCls = 'csis-applymain-bg-blue';
                        return v;
                    }}
            ], {
                grid: 'attachmentName,createdByUser,createdDtmLoc,remark',
                orderBy: 'updatedDtmLoc desc'
            });
            var attachmentGrid = new C.Grid(attachmentDomain, {showNumber: true, paging: true, editing: true});

            var attachmentUploadBatchBtn = Ext.create('Ext.button.Button',{text:CSIS.Lang.ID_252020||'批量上传', icon:'../res/img/themes/default/application_put.png',
                handler:function(){
                    var selRecord = page.getGridBox().getSelectedRecord();
                    if(selRecord==null){
                        Ext.MessageBox.alert('系统提示','请选择一条记录！')
                        return
                    }
                    //获取界面Grid复选框勾选列表
                    var records = [];
                    var checkRecords = page.getGridBox().getCheckedRecords();
                    Ext.each(checkRecords,function(obj,i){
                        records.push(obj)
                    })
                    var params = {}
                    params.records = Ext.JSON.encode(records);//转成JSON
                    params.id = !isEmpty(currentRecord.paymentNoticeId)?currentRecord.paymentNoticeId:currentRecord.feeInvoiceId;
                    params.referenceIdOne = currentRecord.feeInvoiceId;
                    params.referenceModule = "FMM"
                    params.uploadFlag = "fmm"
                    C.fileUploadBoxShow('/file/upload/attachmentFileBatch',function (resp) {
                        Ext.MessageBox.alert('系统提示',resp.msg);
                        if(!isEmpty(currentRecord.paymentNoticeId)) attachmentDomain.getDataSource().loadDataset({referenceId: currentRecord.paymentNoticeId});
                        else attachmentDomain.getDataSource().loadDataset({referenceIdOne: currentRecord.feeInvoiceId});
                    },{maxFileCount:100,//默认最大100个附件
                        params:params,
                        hideTip:true});
                }
            })

            var attachmentViewBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_103920||"查看附件", icon: '../res/img/themes/default/search.png',
                handler: function () {
                    var selectAttachment = attachmentGrid.getSelectedRecord();
                    if (selectAttachment != null && selectAttachment != "") {
                        var fieldName = selectAttachment.attachmentName;
                        var EnquireProgress = new CSIS.UploadWindow();
                        EnquireProgress.startDownload("attachmentFile", fieldName, selectAttachment)
                    } else {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示',  CSIS.Lang.ID_109050||"请选择一条附件记录！")
                    }
                }
            });
            var attachmentCancelBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_100360||"取消", icon: '../res/img/themes/default/cross.gif', disabled: true,
                handler: function () {
                    attachmentDomain.getDataSource().reload();
                    attachmentButtonStatus(false);
                }
            });
            var attachmentSaveBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_116410||"保存附件", icon: '../res/img/themes/default/accept.png', disabled: true,
                handler: function () {
                    attachmentDomain.saveUpdate({callback: function () {
                        attachmentDomain.getDataSource().reload();
                        attachmentButtonStatus(false);
                    }});
                }
            });
            var attachmentRemoveBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_103900||"删除附件", icon: '../res/img/themes/default/table_delete.png',
                handler: function () {
                    var selectAttachment = attachmentGrid.getSelectedRecord();
                    if (selectAttachment != null && selectAttachment != "") {
                        if(companyCode.startWith('080111')){
                            var status = "";
                            if(currentRecord.paymentNoticeId!=null && currentRecord.paymentNoticeId.length>2){
                                C.syncRequest.callAction('list', 'feePaymentNotice',{paymentNoticeId:currentRecord.paymentNoticeId}, function (actionName, domainName, resp) {
                                    if(resp && resp.rows && resp.rows.length > 0) {
                                        status = resp.rows[0].status;
                                    }
                                });
                            }
                            if(status!="" && status!="1"){
                                Ext.MessageBox.alert("提示", "付款单已经有后续领导审核，所以不允许删除附件！（只能领导退单后操作）");
                                return;
                            }
                        }

                        Ext.MessageBox.confirm(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_109080||"是否要删除该附件", function (btn) {
                            if (btn == "yes") {
                                var attachmentFileId = selectAttachment.attachmentFileId;
                                C.syncRequest.callAction('remove', 'attachmentFile', {id: attachmentFileId}, function (action, domain, rsc) {
                                    var msg = rsc.msg;
                                    if (msg == "") {
                                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_109090||"删除成功");
                                        attachmentDomain.getDataSource().reload();
                                    } else {
                                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', msg);
                                    }
                                })
                            }
                        })
                    } else {
                        Ext.MessageBox.alert(CSIS.Lang.ID_162160||'系统提示', CSIS.Lang.ID_109100||"请选择一条附件记录")
                    }
                }
            });

            function sb(resp) { alert("上传失败")}

            var attachmentUploadBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_186330||"上传附件", icon: '../res/img/themes/default/application_put.png',
                handler: function () {
                    var store = page.getGridBox().getSelectedStore();
                    var cg = function(resp){
                        var selectData = page.getGridBox().getSelectedRecord();
                        if(!isEmpty(selectData.paymentNoticeId)){
                            attachmentDomain.getDataSource().loadDataset({referenceId: selectData.paymentNoticeId});}
                        else {attachmentDomain.getDataSource().loadDataset({referenceId: selectData.feeInvoiceId});}
                        console.log("selectData.ifCanUseTax "+selectData.ifCanUseTax)
                        if((selectData.ifCanUseTax=="6"||selectData.ifCanUseTax=="7")&&invoiceCheckCompanyMap[selectData.payer])doProcessSourceFile(resp,selectData)
                    }
                    if (store) {
                        if(companyCode.startWith('080111')){
                            var status = "";
                            var paymentNoticeId = currentRecord.paymentNoticeId;
                            if(paymentNoticeId!=null && paymentNoticeId.length>2){
                                C.syncRequest.callAction('list', 'feePaymentNotice',{paymentNoticeId:currentRecord.paymentNoticeId}, function (actionName, domainName, resp) {
                                    if(resp && resp.rows && resp.rows.length > 0) {
                                        status = resp.rows[0].status;
                                    }
                                });
                            }
                            if(status!="" && status!="1"){
                                Ext.MessageBox.alert("提示", "付款单已经有后续领导审核，所以不允许新增附件！（只能领导退单后操作）");
                                return;
                            }
                        }
                        store.data.referenceModel = "FMM";
                        store.data.uploadFlag = "fmm";
                        store.data.id=!isEmpty(store.data.paymentNoticeId)?store.data.paymentNoticeId:store.data.feeInvoiceId;
                        store.data.referenceIdOne = store.data.feeInvoiceId;
                        attachmentUploadWindow(attachmentDomain, store.data,{successFn: cg, failureFn: sb});
                    } else {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", CSIS.Lang.ID_206560||"请选择记录！")
                    }
                }
            });

            var attachmentTwoUploadBtn = Ext.create("Ext.button.Button", {text: "上传全电发票", icon: '../res/img/themes/default/application_put.png',
                handler: function () {
                    debugger;
                    var store = page.getGridBox().getSelectedStore();
                    if(store==null){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", CSIS.Lang.ID_206560||"请选择记录！")
                        return false;
                    }

                    var selectData = page.getGridBox().getSelectedRecord();
                    if(!(selectData.ifCanUseTax=="6"||selectData.ifCanUseTax=="7")){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", "请选择增值税电子发票！")
                        return false;
                    }

                    if(!invoiceCheckCompanyMap[selectData.payer]){
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", "付款单位必须是已上线的税务系统的公司！")
                        return false;
                    }

                    store.data.referenceModel = "FMM";
                    store.data.uploadFlag = "fmm";
                    store.data.id=!isEmpty(store.data.paymentNoticeId)?store.data.paymentNoticeId:store.data.feeInvoiceId;
                    store.data.referenceIdOne = store.data.feeInvoiceId;
                    store.data.ocrTwoUpload = "two";
                    attachmentTwoUploadWindow(attachmentDomain, store.data,/*{successFn: cg, failureFn: sb}*/);
                }
            })

            var attachmentTwoUploadInputBtn = Ext.create("Ext.button.Button", {text: "全电发票录入", icon: '../res/img/themes/default/application_put.png',
                handler: function () {
                    var storeData = {};
                    storeData.referenceModel = "FMM";
                    storeData.uploadFlag = "fmm";
                    storeData.ocrTwoUpload = "twoInput";
                    var cg = function(response){
                        debugger;
                        tabs.setActiveTab(1);
                        Ext.getElementById(page.getToolbarBox().getButton('create').getId()).click();
                        var returnObj = eval(response.result);
                        var invoiceNo = returnObj.extend.invoiceNo;
                        var invoiceCode = returnObj.extend.invoiceCode;
                        var invoiceDate  = returnObj.extend.invoiceDate;
                        var amount = returnObj.extend.amount;
                        var dtlAmount = returnObj.extend.dtlAmount;
                        var taxAmount  = returnObj.extend.taxAmount;

                        var dtlTaxAmount  = returnObj.extend.dtlTaxAmount;
                        var amountWithoutTax  = returnObj.extend.amountWithoutTax;
                        var dtlAmountWithoutTax  = returnObj.extend.dtlAmountWithoutTax;
                        var scScanId  = returnObj.extend.scScanId;
                        var salesName  = returnObj.extend.salesName;
                        var purchaserName  = returnObj.extend.purchaserName;
                        var taxCheckState  = returnObj.extend.taxCheckState;
                        var invoiceType  = returnObj.extend.invoiceType;

                        salesName = replacePayeeName(salesName);
                        purchaserName = replacePayeeName(purchaserName);
                        page.getEditBox().getExtField('invoiceNo').setValue(invoiceNo);
                        page.getEditBox().getExtField('invoiceCode').setValue(invoiceCode);
                        page.getEditBox().getExtField('invoiceDate').setValue(invoiceDate);
                        page.getEditBox().getExtField('dtlAmountWithoutTax').setValue(dtlAmountWithoutTax);
                        page.getEditBox().getExtField('amountWithoutTax').setValue(amountWithoutTax);
                        page.getEditBox().getExtField('dtlTaxAmount').setValue(dtlTaxAmount);
                        page.getEditBox().getExtField('taxAmount').setValue(taxAmount);
                        page.getEditBox().getExtField('dtlAmount').setValue(dtlAmount);
                        page.getEditBox().getExtField('amount').setValue(amount);
                        page.getEditBox().getExtField('ifCanUseTax').setValue(invoiceType);
                        page.getEditBox().getExtField("currency").setComboValue("CNY","人民币");
                        tempFields.put('currencyName', "人民币");
                        page.getEditBox().getExtField('baseAmount').setValue(dtlAmount);
                        var amountWithoutTax = Number(page.getEditBox().getValue('amountWithoutTax'));
                        var taxAmount = Number(taxAmount);//有可能编辑区计算未赋值导致计算税率失败
                        page.getEditBox().getExtField("taxRate").setValue((accDiv(taxAmount, amountWithoutTax).toFixed(2)));
                        page.getEditBox().getExtField('taxCheckState').setValue(taxCheckState);
                        page.getEditBox().getExtField('scScanId').setValue(scScanId);
                        if (taxCheckState == '0') {
                            setBoxReadOnlyEx(page.getEditBox(),true,"amount,taxAmount,amountWithoutTax,invoiceCode,invoiceDate,currency,ifCanUseTax,taxRate");
                        }
                    }
                    attachmentTwoUploadWindow(attachmentDomain, storeData,{successFn: cg});
                }
            })

            var attachmentEditBtn = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_109030||"编辑附件", icon: '../res/img/themes/default/table_delete.png',
                handler: function () {
                    if (attachmentDomain.getDataSource().getCount() == 0) {
                        Ext.MessageBox.alert(CSIS.Lang.ID_117530||"提示", CSIS.Lang.ID_116430||"附件中没有数据！");
                        return false
                    }
                    var rowIndex = attachmentDomain.getDataSource().indexOf(attachmentGrid.getUI().getSelectionModel().getSelection()[0]);
                    var delay = new Ext.util.DelayedTask(function () {
                        if (rowIndex < 0)
                            attachmentGrid.getCellEditing().startEdit(0, 4);
                        else
                            attachmentGrid.getCellEditing().startEdit(rowIndex, 4);

                    });
                    delay.delay(10);
                    attachmentButtonStatus(true);
                }
            });

            attachmentGrid.addToPagingBar(attachmentViewBtn);
            attachmentGrid.addToPagingBar(attachmentCancelBtn);
            attachmentGrid.addToPagingBar(attachmentSaveBtn);
            attachmentGrid.addToPagingBar(attachmentRemoveBtn);
            attachmentGrid.addToPagingBar(attachmentEditBtn);
            attachmentGrid.addToPagingBar(attachmentUploadBtn);
            attachmentGrid.addToPagingBar(attachmentTwoUploadBtn);

            attachmentGrid.addListener("cellediting", function (grid, field) {
                if (attachmentSaveBtn.disabled) { return false;}
                if (field != 'remark') { return false }
            });

            function attachmentButtonStatus(falg) {
                attachmentUploadBtn.setDisabled(falg);
                attachmentEditBtn.setDisabled(falg);
                attachmentRemoveBtn.setDisabled(falg);
                attachmentSaveBtn.setDisabled(!falg);
                attachmentCancelBtn.setDisabled(!falg);
            }
            attachmentSaveBtn.setDisabled(true);
            attachmentCancelBtn.setDisabled(true);
            var attachmentPanel = Ext.create('Ext.panel.Panel', {
                layout: 'fit',
                items: [attachmentGrid.getUI()],
                title: CSIS.Lang.ID_119500||'附件'
            });
            page.getEditBox().getEditArea().getUI().add(attachmentPanel);
            //添加附件双击监听
            attachmentGrid.addListener('cellDoubleClick', function (grid, event, record, rowIndex, cellIndex){
                var fileName = encodeURIComponent(record.attachmentName);
                var fileType =  fileName.substring(fileName.lastIndexOf('.') + 1);
                var token = '_t' + Math.random();
                var downloadUrl ="http://"+location.host+"/file/download/feeAttachment?token=" + token + "&attachmentFilePath=" + record.attachmentFilePath;
                window.open(C.fileOnlineViewPath+"?ft="+fileType+"&fn="+currentRecord.claimNo+"&url="+encodeURIComponent(downloadUrl));
            });
            // 刷新附件
            function refreshPanelVoyageInfoAccessoriesFee(src) {
                var item = src.items.items[0];
                if (!item) {
                    return false;
                }
                var selRecord = page.getGridBox().getSelectedRecord();
                if(selRecord==null){
                    Ext.MessageBox.alert('系统提示','请选择一条记录！')
                    return
                }
                DragFileUpload.addDragEvent({
                    id:item.id,
                    maxFileCount:10,
                    uploadurl: '/file/upload/attachmentFileBatch',
                    params : {
                        referenceIdOne: currentRecord.feeInvoiceId,
                        referenceModel: "FMM",
                        uploadFlag:"fmm",
                        id:!isEmpty(currentRecord.paymentNoticeId)?currentRecord.paymentNoticeId:currentRecord.feeInvoiceId
                    },
                    callback: function(resp) {
                        DragFileUpload.showMessage(resp);
                        if(!isEmpty(currentRecord.paymentNoticeId)) attachmentDomain.getDataSource().loadDataset({referenceId: currentRecord.paymentNoticeId});
                        else attachmentDomain.getDataSource().loadDataset({referenceIdOne: currentRecord.feeInvoiceId});
                    }
                });
            }
            attachmentPanel.addListener('activate',function (src) {
                // 刷新附件列表
                refreshPanelVoyageInfoAccessoriesFee(src);
            });
            /***附件************************** 结束*/

            //税控发票验证结果tab。addon240126
            var taxVerifyResultDomain = getTaxVerifyResultDomain();
            var taxVerifyResultGrid = new C.Grid(taxVerifyResultDomain, {showNumber: true, paging: true});

            var taxVerifyResultTab = new taxVerifyResultUI(taxVerifyResultGrid);
            page.getEditBox().getEditArea().getUI().add(taxVerifyResultTab.getUI());
            attachmentGrid.addListener('rowSelected', function (grid, event, record) {
                if(record) taxVerifyResultDomain.getDataSource().loadDataset({referenceId:record.attachmentFileId})
                else taxVerifyResultDomain.getDataSource().loadDataset({referenceId:'SSMPSSMP'})
            });
            //end


                        if(companyCode.startWith('0802')) {
                            //海图账单明细tab add20240701 yibo
                            var fmmFeeInvoiceSeachatDtlDomain = getSeaChartDomain();
                            var fmmFeeInvoiceSeachatDtlGrid = new C.Grid(fmmFeeInvoiceSeachatDtlDomain, {
                                showNumber: true,
                                paging: true
                            });

                            var fmmFeeInvoiceSeachatDtlTab = new seaChartUI(fmmFeeInvoiceSeachatDtlGrid);
                            page.getEditBox().getEditArea().getUI().add(fmmFeeInvoiceSeachatDtlTab.getUI());
                        }

            /***关联港使费附件************************** 开始*/
            var gsfAccessoriesDomain = new CSIS.Domain('voyageInfoAccessories', [
                {name: 'voyageInfoAccessoriesId'},
                {name: 'voyageInfoId'},
                {name: 'vesselCode', display: '船舶'},
                {name: 'attachmentName', display: '附件名称',width:200,readOnly:true},
                {name: 'attachmentType', display: '附件类型'},
                {name: 'attachmentId', display: '附件ID'},
                {name: 'isOther', display: ''},
                {name: 'uploadUser', display: '上传用户',readOnly:true},
                {name: 'uploadTime', display: '上传时间',type:'date',format:'Y-m-d',readOnly:true},
                {name: 'remark', display: '备注',width:250,
                    render:function(v,meta){
                        meta.tdCls = 'csis-applymain-bg-blue';
                        return v;
                    }}
            ], {
                grid: 'attachmentName,remark,uploadUser,uploadTime',
                orderBy: 'uploadTime desc'
            });

            var xmAccessoriesPage = new CSIS.WorkPageBox(gsfAccessoriesDomain, {
                search: false,
                edit:false,
                toolbarPos:"bottom",
                gridBoxConfig:{paging: true,editing:false},
                toolbar: false,
            });

            var attaVViewXm = Ext.create("Ext.button.Button", {text: CSIS.Lang.ID_103920||"查看附件", icon: '../res/img/themes/default/search.png',
                handler:function(){
                    var selectAttachment = xmAccessoriesPage.getGridBox().getSelectedRecord();
                    if (selectAttachment != null && selectAttachment != "") {
                        var fieldName = selectAttachment.attachmentName;
                        var EnquireProgress = new CSIS.UploadWindow()
                        EnquireProgress.startDownload("omsTillHeaderAccessories", fieldName, selectAttachment)
                    } else {
                        Ext.MessageBox.alert("系统提示", "请选择一条附件记录！")
                    }
                }
            });

            xmAccessoriesPage.getGridBox().addToPagingBar(attaVViewXm);

            xmAccessoriesPage.getGridBox().addListener('cellDoubleClick', function (grid, event, record, rowIndex, cellIndex) {
                // 双击下载附件
                attaVViewXm.handler();
            });

            function refreshAccessories() {
                gsfAccessoriesDomain.getDataSource().clearRecords();
                var invoiceRecord = page.getGridBox().getSelectedRecord();
                if (!invoiceRecord) {
                    return false;
                }
                var paymentNos = "";
                if (invoiceRecord.invoiceNo) {
                    paymentNos += "'" + invoiceRecord.invoiceNo + "',";
                }
                if (invoiceRecord.orderNo) {
                    paymentNos += "'" + invoiceRecord.orderNo + "',";
                }
                if (paymentNos) {
                    paymentNos = paymentNos.substring(0, paymentNos.length - 1);
                    console.log(paymentNos)
                    C.syncRequest.callAction("list", 'freightDetail', {_extend : " and actualFeePaymentNoticeId in (" + paymentNos + ")"}, function (actionName, domainName, resp) {
                        if (resp && resp.total > 0 && resp.rows[0].unionFeePaymentNoticeId) {
                            var unionFeePaymentNoticeIds = [];
                            Ext.each(resp.rows,function (item,index) {
                                if (item.unionFeePaymentNoticeId && !Ext.Array.contains(unionFeePaymentNoticeIds,item.unionFeePaymentNoticeId)) {
                                    unionFeePaymentNoticeIds.push(item.unionFeePaymentNoticeId);
                                }
                            })
                            if (unionFeePaymentNoticeIds && unionFeePaymentNoticeIds.length > 0) {
                                var nos = "";
                                Ext.each(unionFeePaymentNoticeIds,function (no,index) {
                                    if (no) {
                                        nos += "'" + no + "',";
                                    }
                                })
                                nos = nos ? nos.substring(0, nos.length - 1) : "";
                                gsfAccessoriesDomain.getDataSource().loadDataset({'attachmentType.eq':"S",_extend : " and voyageInfoId in (" + nos + ")"},1);
                            }
                        }
                    });
                }
            }

            xmAccessoriesPage.getGridBox().getPagingUI().items.get("refresh").handler = function(){
                refreshAccessories();
            }

            var gsfAccessories = Ext.create('Ext.panel.Panel',{
                layout:'fit',
                items: [xmAccessoriesPage.getUI()],
                title:'关联港使费附件'
            });
            if (xiamenFlag) {
                page.getEditBox().getEditArea().getUI().add(gsfAccessories);
            }
            /***关联港使费附件************************** 结束*/

            var editPanel = Ext.create('Ext.panel.Panel', {
                region:'center',
                items:page.getEditBox().getUI(),
                layout: 'border',
                split:false,
                bbar: [
                    page.getToolbarBox().getUI(),
                    btnNegReversal_sub,btnPaymentNotice_sub,btnOperation_sub,
                    scanBtn,doubtOrRevokeBtn_sub,rejectInvoiceBtn_sub,attachmentTwoUploadInputBtn,infoPrintBtn,dataModBtn]});
            var gridtoolbarBar = Ext.create('Ext.toolbar.Toolbar', {
                items: [btnMainAdd,btnMainEdit,btnMainRemove,btnNegReversal,btnPaymentNotice,commitOABtn,btnOperation,printBtn,
                    excelBtn,btnExport,btnSendAuditBill,btnSendFincBill,rebackUpdateBtn,doubtOrRevokeBtn,rejectInvoiceBtn,btnViewInnerOrder,importExcelByDgf,copyFeeInvoiceBtn] });
            var mainPanel1 = Ext.create('Ext.panel.Panel', {
                layout: 'border',
                items: [page.getSearchBox().getUI(),page.getGridBox().getUI()],
                title: CSIS.Lang.ID_251880||'发票列表',
                bbar:gridtoolbarBar
            });
            var mainPanel2 = Ext.create('Ext.panel.Panel', {
                layout: 'border',
                region:'center',
                items: [editPanel,tabPanel1],
                bbar: toolbarSub,
                title: CSIS.Lang.ID_119080||'详细信息'
            });
            var tabs = Ext.create('Ext.tab.Panel',{
                region:'center',
                layout:'border',
                items:[mainPanel1,mainPanel2]
            });
            C.currentWorkPage.add(tabs);
            tabs.addListener('beforetabchange', function(tabPanel, newCard, oldCard) {
                var pageSaveBtn = page.getToolbarBox().getButton('save');
                if(!pageSaveBtn.disabled) {
                    Ext.MessageBox.alert("系统提示","请先保存记录\n或者取消当前编辑的内容。");
                    return false;
                }
            });
            page.getGridBox().addListener("cellDoubleClick",function(){
                btnStatus="double";
                tabs.setActiveTab(1);
            });
            tabs.addListener('tabchange', function(tabPanel, newCard, oldCard) {
                if(newCard.title == (CSIS.Lang.ID_119080||'详细信息')){
                    if(currentRecord!=null){
                        if (btnStatus!="create") { changeGrid(currentRecord); }
                    }
                }
            });

            //隐藏控件
            for(var i =10;i<22;i++) {
                if(page.getToolbarBox().getUI().getComponent(i)!=null){
                    page.getToolbarBox().getUI().getComponent(i).hide();
                } };

            if(currentId=="ff8080815a35be42015a35cb71860001"){ //通导模块
                //yangxl 2018-10-14 通导发票录入默认查询录入日期为本年1月1日
                var inputDate = new Date()
                inputDate.setDate(1)
                inputDate.setMonth(0)
                page.getSearchBox().setValue('inputDate.from',inputDate);
                page.getSearchBox().getExtField("invoiceSort").setComboValue("FY67", CSIS.Lang.ID_139490||"通导修备费");
                //setBoxReadOnlyEx(page.getSearchBox(),true,"invoiceSort");
            }else{  page.getSearchBox().setValue('inputDate.from',new Date());  }
            page.getSearchBox().setValue('inputDate.to',new Date());
            page.getSearchBox().setValue('inputUser',userName);
            page.getSearchBox().getExtField('amount').setFieldLabel(CSIS.Lang.ID_112530||'发票总金额');
            function setComboGrid(eb) {  //为界面上的下拉Grid赋值
                if (currentRecord == null) return;
                eb.getExtField("vesselCode").setComboValue(currentRecord.vesselCode, currentRecord.vesselName)
                eb.getExtField("payer").setComboValue(currentRecord.payer, currentRecord.customerName)
                eb.getExtField("invoiceSortDetail").setComboValue(currentRecord.invoiceSortDetail, currentRecord.freightName)
                eb.getExtField("invoiceSort").setComboValue(currentRecord.invoiceSort, currentRecord.freightTypeName)
                if (isCreate && !isEmpty(currentRecord.invoiceSortDetail)) {
                    setGroupSortAndDetailByInvoiceSortDetail(currentRecord.invoiceSortDetail)
                } else {
                    eb.getExtField("groupSortDetail").setComboValue(currentRecord.groupSortDetail, currentRecord.groupSortDetailName)
                    eb.getExtField("groupSort").setComboValue(currentRecord.groupSort, currentRecord.groupSortName)
                }
                eb.getExtField("unit").setComboValue(currentRecord.unit, currentRecord.unitName)
                eb.getExtField("currency").setComboValue(currentRecord.currency, currentRecord.currencyName)
                eb.getExtField("payee").setComboValue(currentRecord.payee, currentRecord.payeeName)
                if (eb.getExtField("director")) {
                    eb.getExtField("director").setComboValue(currentRecord.director, currentRecord.usrName)
                }
                eb.getExtField("taxRate").setComboValue("" + currentRecord.taxRate, "" + currentRecord.taxRateName)
                eb.getExtField("department").setComboValue(currentRecord.department, currentRecord.departmentName)
                if (currentRecord.taxRate == '0')  eb.getExtField("taxRate").setComboValue("0", "0")   //值为0的时候直接编辑保存会提示没有值
                //去除新增状态的时候用当前选中行状态覆盖新增初始化为1的状态
                if (currentRecord.invoiceStatus != null && !isCreate) {
                    var invoiceStatusName;
                    if (currentRecord.invoiceStatus == '1') invoiceStatusName = CSIS.Lang.ID_115590 || "新增";
                    else if (currentRecord.invoiceStatus == '3')invoiceStatusName = CSIS.Lang.ID_119620 || "未审核";
                    else if (currentRecord.invoiceStatus == '4')invoiceStatusName = CSIS.Lang.ID_110270 || "已审核";
                    else if (currentRecord.invoiceStatus == '5')invoiceStatusName = CSIS.Lang.ID_115630 || "已付款";
                    eb.getExtField("invoiceStatus").setComboValue(currentRecord.invoiceStatus, invoiceStatusName);
                }
                if (youlunFlag) {
                    eb.getExtField("portCode").setComboValue(currentRecord.portCode, currentRecord.portName);
                    eb.getExtField("srcOrderType").setComboValue(currentRecord.srcOrderType, currentRecord.srcOrderTypeName);
                }
                if (companyCode.startWith("68")) {
                    if (currentRecord.invoiceSort && currentRecord.invoiceSort == "FY72") {
                        maintainTotalAmount("rowselected", currentRecord.maintainPrimerQty, currentRecord.maintainOtherQty);
                    } else if (currentRecord.invoiceSort && currentRecord.invoiceSort == "FY76") {
                        dockTotalAmount("rowselected", currentRecord.dockSelfPolishingQty, currentRecord.dockOtherQty)
                    }
                }
            }
                function getDirector(frightType, userCompany, vesselCode) {
                    var director = "";
                    if (!isEmpty(frightType) && !isEmpty(userCompany) && !isEmpty(vesselCode)) {
                        if (!bndFlag) {
                            C.syncRequest.callAction("getDirectorByCondition", 'freightTypeOrganization', {
                                frightType: frightType,userCompany: userCompany,vesselCode: vesselCode
                            }, function (actionName, domainName, resp) {
                                if (resp != null) {
                                    director = resp.msg;
                                }
                            });
                        }

                    }
                    return director;
                }

                function getJgInnerOrderNoByInDetail(invoiceSortDetail, vesselCode, foreStatMonth) {
                    var innerNo = "";
                    if (!isEmpty(companyCode) && companyCode.substring(0, 4) == '6600' && !isEmpty(invoiceSortDetail) && (invoiceSortDetail == 'FY61001'
                            || invoiceSortDetail == 'FY61201' || invoiceSortDetail == 'FY04021') && !isEmpty(vesselCode) && !isEmpty(foreStatMonth)) {  //
                        if (!isEmpty(vesselCode) && !isEmpty(foreStatMonth)) {
                            C.syncRequest.callAction("getJgInnerOrderNoByInDetail", 'jgInnerOrder', {
                                year: foreStatMonth,invoiceSortDetail: invoiceSortDetail,vesselCode: vesselCode
                            }, function (actionName, domainName, resp) {
                                if (resp != null && resp.msg != null) {
                                    innerNo = resp.msg;
                                }
                            });
                        }
                    }
                    return innerNo;
                }

                var _extendParams = "";
                var initParamsString = "";
                if (userCode)  initParamsString += " AND mms.userCode='" + userCode + "'";
                if (menuNo) initParamsString += " AND mms.menuNo='" + menuNo + "'";
                C.ajax.callAction("getSelectedCount", 'multiShipSelected', {userCode: userCode,sysid: "",menuNo: menuNo},
                        function (actionName, domainName, resp) {
                    if (resp.success) {
                        if (parseInt(resp.msg) > 0)
                            _extendParams = " AND EXISTS(select 1 from com.csis.ssmp.sys.domain.MultiShipSelected mms WHERE mms.vesselCode=mtbl.vesselCode" + initParamsString + ")";
                    }
                });
            tabs.setActiveTab(1);
            tabs.setActiveTab(0);
            //初始化编辑区不可编辑
            page.getEditBox().setBoxReadOnly(true)
            //初始化按钮权限
            setButtonStatus(null)
            setButtonStatus('create', true);
            setButtonStatus('btnExport', true)
            setButtonStatus('rebackUpdateBtn', true)
            setButtonStatus('attachmentTwoUploadInputBtn', true)
            setButtonStatus('attachmentTwoUploadBtn', true)
            if (!companyCode.startWith("660000")) {
                dataModBtn.hide();
            }


            //   备件，物料 订购,完工,通导，航修，航修通导（航修修理）跳转加载数据
            if (!isEmpty(enquireNo) && !isEmpty(enquireType)) {
                    var count = 0;
                    if (enquireType == "WG") {
                        feeInvoiceDomain.getDataSource().loadDataset({"_extend": " and vesselCode='" + pageVesselCode + "' and (innerOrder='" + enquireNo + "' or  feeInvoiceId  in (select k.feeInvoiceId from OperationRelevance k where k.relatedId='" + completionReportId + "') )"})
                    } else if (enquireType == "TD") {
                        feeInvoiceDomain.getDataSource().loadDataset({"_extend": " and vesselCode='" + pageVesselCode + "' and innerOrder='" + enquireNo + "' "})
                    }else if (enquireType == "HXTD") {
                        feeInvoiceDomain.getDataSource().loadDataset({"_extend": " and vesselCode='" + pageVesselCode + "' and innerOrder='" + enquireNo + "' "})
                    } else if (enquireType == "WL"||enquireType == "HX"||enquireType == "HXZJ"||enquireType == "HHZL") {
                        feeInvoiceDomain.getDataSource().loadDataset({"_extend": " and innerOrder='" + enquireNo + "' "})
                    }else {
                        feeInvoiceDomain.getDataSource().loadDataset({"_extend": " and innerOrder='" + enquireNo + "' "})
                    }
                    feeInvoiceDomain.getDataSource().addListener("load", function (store, records, successful, eOpts) {
                        count = store.getCount();
                        if (count == 0) {
                            tabs.setActiveTab(1);
                            Ext.getElementById(page.getToolbarBox().getButton('create').getId()).click();
                            if (enquireType == 'WG') {
                                WGaddBjOrder()
                            } else if (enquireType == 'TD') {
                                TDaddBjOrder()
                            } else if (enquireType == "HX") { //航修审计
                                if(cusType == 'GD'){
                                    GDaddBjorder()
                                }else{
                                    HXaddBjorder()
                                }
                            } else if (enquireType == "HXTD") {  //航修通导
                                HXTDaddBjorder()
                            } else if (enquireType == "HXZJ") {  //航修总结
                                HXZJaddorder()
                            } else if (enquireType == "WL") {
                                isWlOrderCreate = true;
                                addWLOrder()
                            }  else if(enquireType == "HHZL"){
                                addHHZLOrder()
                            }else {
                                isBjOrderCreate = true;
                                addBjOrder()
                            }
                        } else {
                            tabs.setActiveTab(1);
                        }
                    });
                    page.getEditUI().setVisible(true);
                }
                //机务费用明细跳转
                var dssParm = C.context.get('dssParm');
                C.context.unRegister('dssParm');
                scanBtn.disable()
                if (dssParm) {
                    var arrayParm = dssParm.split(',');
                    page.getSearchUI().getForm().reset();
                    if (!(arrayParm[1] == "null")) {
                        page.getSearchBox().getExtField('vesselCode').setComboValue(arrayParm[1], arrayParm[2])
                    }
                    page.getSearchBox().getExtField('invoiceNo').setValue(arrayParm[3])
                    Ext.getElementById(page.getSearchBox().getSearchButton().getId()).click()
                }
            //船名记忆
            var ifVesMemory = <%=session.getAttribute("ifVesMemory")%>;
            if (C.vessel && C.vessel.vesselCode && ifVesMemory) {
                page.getSearchBox().getExtField('vesselCode').setComboValue(C.vessel.vesselCode, C.vessel.vesselName)
            }
            if(!isEmpty(orderNo) ){
                feeInvoiceDomain.getDataSource().loadDataset({feeInvoiceId:orderNo});
            }
            if(!isEmpty(recordDataId) ){
                feeInvoiceDomain.getDataSource().loadDataset({feeInvoiceId:recordDataId});
            }
            if(!permissionMap.containsKey('importExcelByDgf')) {
                importExcelByDgf.destroy()
            }
            if(!permissionMap.containsKey('copyFeeInvoiceBtn')) {
                copyFeeInvoiceBtn.destroy()
            }

            if (!isEmpty(rpt_order_no)) {
                page.getSearchUI().getForm().reset();
                if (rpt_order_no.indexOf(",") > -1) {
                    rpt_order_no = rpt_order_no.replaceAll(",", "','")
                    rpt_order_no = "'" + rpt_order_no + "'"
                    var _extend = " and invoiceNo in(" + rpt_order_no + ")"
                    feeInvoiceDomain.getDataSource().loadDataset({_extend: _extend})
                } else {
                    page.getSearchBox().getExtField('invoiceNo').setValue(rpt_order_no);
                    if (!isEmpty(rpt_inner_order)) {
                        page.getSearchBox().getExtField('innerOrderSearch').setValue(rpt_inner_order);
                    }
                    Ext.getElementById(page.getSearchBox().getSearchButton().getId()).click();
                }
            }
            if(companyCode.startWith("6600")){
                dataModBtn.hide();
            }

        })
    });
</script>
